字符串复制函数
char * strcpy(char * s1, const char * s2);
char* strcpy(char* s1, const char* s2){
int i=0;while(s2[i]!='\0'){
s1[i] = s2[i];
i++;
}
s1[i]='\0';
return s1;
}
字符串长度函数
unsigned int strlen(const char * s);
\0不计算在内。
字符串连接函数
char * strcat(char * s1, const char * s2);
char * strcat(char * s1, const char * s2){
int i=0;
while(s1[i] != '\0')
i++;
while(*s2 != '\0'){
s1[i++] = *s2++;
}
s1[i] = '\0';
return s1;
}
字符串比较函数
int strcmp(char * s1, const char * s2);
int strcmp(char * s1, const char * s2){
int i=0;
while(*(s1+i)!='\0' && *(s2+i)!='\0'){
if (s1[i]!=s2[i])
break;
i++;
}
if (s1[i]>s2[i])
return 1;
else if (s1[i]<s2[i])
return -1;
else
return 0;
}