第一种方法:统计输入字符串的长度
#include<stdio.h>
#include<string.h>
int main()
{
char buff[100]={0};
printf("请输入一个字符串:\t");
scanf("%s",&buff);
printf("你输入字符串的个数为:\t%d\n ",strlen(buff));
}
第二种方法:遍历输入字符串,直到结束字符'\0'
#include<stdio.h>
void main()
{
char str[1000],*p;
int word=0;
printf("请输入一个字符串:\t");
gets(str);
for(p=str;*p!='\0';p++)
word++;
printf("输入字符串的长度为:\t%d\n",word);
}
温馨提示:答案为网友推荐,仅供参考