当前位置:网站首页>Count the number of words in a line of string and take it as the return value of the function

Count the number of words in a line of string and take it as the return value of the function

2022-06-26 16:44:00 Muzi..

#include<stdio.h>
#include<string.h>
#define N 80
int fun(char *s);
int main()
{
    
	 
	 char line[N];
	 int num=0;
	 printf("enter a string:\n");
	 gets(line);
	 num=fun(line);
	 printf("the number of words is:%d\n\n",num);
	
	 
}
int fun(char *s)
{
    
	 int i,j;
	 for(i=0;s[i]!='\0';i++)
	 
	 	 if(s[i]!=' '&&(s[i+1]==' '||s[i+1]=='\0'))
	 	     j++;
	 	     
	 
	 return j;
}
原网站

版权声明
本文为[Muzi..]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170506478378.html