Advertisement

c语言程序--读取输入字符串并计算其中的单词数量(以空格分割)

阅读量:
复制代码
    #include <stdio.h>
    int main()
    {
    	char string[81];
    	int i,num=0,word=0;
    	char c;
    	gets(string);
    	for(i=0;(c=string[i])!='\0';i++)
    		if(c==' ') word=0;
    		else if (word==0)
    		{
    			word=1;
    			num++;
    		}
    	printf("there are %d words in this line .\n",num);
    	return 0;
    }
    
    
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
      
    
在这里插入图片描述

全部评论 (0)

还没有任何评论哟~