抄了一个计算字符串个数的程序,一个很简单的代码。但是能看懂,也能掌握使用。原谅我菜,抽出一个小时看几段代码也好

#include<stdio.h>
main()
{
char string[100];
int index,word=1;
char blank;
gets(string);
if(string[0]=='\0')
{
printf("there is no char!\n");
}
else if(string[0]==' ')
{
printf("first char just is a blank!\n");
}
else
{
for(index=0;string[index]!=0;index++)
{
blank=string[index];
if(blank==' ')
{
word++;
}
printf("%d\n",word);
}
return 0;
 } 

猜你喜欢

转载自www.cnblogs.com/redxi/p/10836041.html
今日推荐