当前位置:网站首页>6-1 how many words are needed to form a sentence?

6-1 how many words are needed to form a sentence?

2022-06-11 17:37:00 Tomatoes_ Menon

This question requests to realize a function , Count the number of words in a string .

Function interface definition :

int fun ( char *s );

Sample referee test procedure :

 Here is an example of a function being called for testing . for example :
#include <stdio.h>

int  fun ( char *str );

int main()
{

 char str[20];

  gets(str);

  printf("%d",fun(str));

  return 0;

}

/*  Please fill in the answer here  */

sample input :

how are you

sample output :

3
int  fun ( char *s )
{
    int count=0;
    int i=0;
    while(s[i]){
        if(s[i]==' ')
            count++;
         i++;
    }
    return count+1;
}

 

原网站

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