|
|
发表于 2012-2-23 12:57:52
|
显示全部楼层
本帖最后由 「hailmy」 于 2012-2-23 12:59 编辑
我写的是这样。。。
#include <stdio.h>
#include <string.h> //strcpy 头文件
#include <stdlib.h> //malloc 头文件
int main()
{
char *str1 = "abcde";
char *str2;
str2 = (char *)malloc( sizeof(str1)); //初始化 str2
int i = 0;
strcpy(str2, str1);
printf("%s\n", str1);
//计算str2 长度
while (*(str2+i) != '\0')
i++;
printf("%d\n", i);
return 0;
}
/*
输出结果:
----------------------------------------
abcde
5
Press any key to continue
----------------------------------------
*/ |
|