?? 18.c
字號:
#include<stdio.h>
/*實現從源字符串string到目的字符串str的復制函數*/
char *stringcpy(char *str,const char *string)
{
char *s=str;
while(*string)
*s++=*string++;
*s='\0';
/*返回目的字符串的首地址*/
return str;
}
/*將字符串string連接到字符串str的尾部*/
char *stringcat(char *str,const char *string)
{
char *s=str;
/*找到字符串str的尾部*/
while(*s)
s++;
while(*string)
*s++=*string++;
*s='\0';
/*返回目的字符串的首地址*/
return str;
}
/*
實現兩個字符串str和string的比較
如果str小于string返回負值,
如果str大于string返回正值,
如果str等于string返回0
*/
int stringcmp(const char *str,const char *string)
{
while((*str)&&(*string)&&(*str==*string))
{
str++;
string++;
}
return (int)(*str-*string);
}
int main()
{
char s1[20];
const char *s2="I love ";
const char *s3="china";
char *pc;
int cmp;
clrscr();
puts("***********************************");
puts("| The program will complish: |");
puts("| strcpy,strcat,strcmp |");
puts("***********************************");
printf("The string s2 is:%s\n",s2);
printf("The string s3 is:%s\n\n",s3);
pc=stringcpy(s1,s2);
printf("After stringcpy s2 to s1,s1 is:\n");
puts(pc);
pc=stringcat(s1,s3);
printf("After stringcat s1 and s3,s1 is:\n");
puts(pc);
cmp=stringcmp(s2,s3);
if(cmp==0)
printf("\nThe string s2 is equal to s1\n");
else if(cmp<0)
printf("\nThe string s2 is smaller to s1\n");
else
printf("\nThe string s2 is larger to s1\n");
getch();
return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -