1、strcpy
①运行
②代码
#include <my_h.h>
int my_strcpy(char *s1,const char *s2)
{
while(*s2!=0)
{
*s1=*s2;
s1++;
s2++;
}
*s1=*s2;
}
int main(int argc, const char *argv[])
{
char s1[100]="hello";
char s2[100]="world";
my_strcpy(s1,s2);
printf("%s\n",s1);
return 0;
}
2、strlen
①运行
②代码
#include <my_h.h>
int main(int argc, const char *argv[])
{
char s[]="hello";
int i=0;
while(s[i]!=0)
i++;
printf("%d\n",i);
return 0;
}
3、strcmp
①运行
②代码
#include <my_h.h>
int main(int argc, const char *argv[])
{
char s1[100]="1234567890";
char s2[]="12345";
int i=0;
while(s1[i]==s2[i])
i++;
if(s1[i]-s2[i]>0)
printf("%s>%s",s1,s2);
else if(s1[i]-s2[i]<0)
printf("%s<%s",s1,s2);
else if(s1[i]-s2[i]==0)
printf("%s=%s",s1,s2);
return 0;
}
4、strcat
①运行
②代码
#include <my_h.h>
int main(int argc, const char *argv[])
{
char s1[100]="hello";
char s2[]="world";
int i=0;
while(s1[i]!=0)
i++;
int j=0;
while(s2[j]!=0)
s1[i++]=s2[j++];
s1[i]=s2[j];
printf("%s\n",s1);
return 0;
}