码迷,mamicode.com
首页 > 其他好文 > 详细

各种字符串函数(strcpy,strcmp,strlen)之深度剖析

时间:2014-05-18 09:47:40      阅读:273      评论:0      收藏:0      [点我收藏+]

标签:style   c   int   a   for   har   

//字符串复制函数1

void strcpy1(char str1[], char str2[]){

int i = 0;
for (; str2[i] != ‘\0‘; i++){
str1[i] = str2[i];
}
str1[i] = ‘\0‘;

}

//2

void strcpy2(char str1[], char str2[]){
int i = 0;
while (str1[i] = str2[i])i++;

}

//字符串长度函数1

int strlen1(char str[]){
int i = 0;
while (str[i] != ‘\0‘)i++;
return i;
}

//2
int strlen2(char *str){
char *t = str;
while (*str != ‘\0‘){
str++;
}
return str - t;
}

//字符串比较函数1
int strcmp1(char str1[], char str2[]){
int i = 0;
for (; str1[i] != ‘\0‘; i++){
if (str1[i] != str2[i])break;
}
return str1[i] - str2[i];
}

//2
int strcmp2(char *str1, char *str2){
for (; *str1 != ‘\0‘; str1++, str2++){
if (*str1 != *str2)break;
}
return *str1 - *str2;
}

各种字符串函数(strcpy,strcmp,strlen)之深度剖析,布布扣,bubuko.com

各种字符串函数(strcpy,strcmp,strlen)之深度剖析

标签:style   c   int   a   for   har   

原文地址:http://blog.csdn.net/eh_sky/article/details/26011007

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!