69,373
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <stdlib.h>
int charlength(char *ps)
{
int length=0;
while(*(ps+length)!='\0')
{
length++;
}
return(length);
}
void main()
{
char *pc = (char *)malloc(sizeof(char) * 80);
if (!pc)
return -1;
printf("请输入一个字符串:");
scanf("%s",pc);
printf("\n\n您刚才输入的字符串%s长度为:%d。\n\n",pc,charlength(pc));
free(pc);
system("pause");
}
参考一下吧~