程序設(shè)計:
請編寫函數(shù) fun,該 函數(shù)的功能是:統(tǒng)計一行字符串中單詞的個數(shù),作為函數(shù)值返回。一行字符串在主函數(shù)中輸入,規(guī)定所有單詞由小寫字母組成,單詞之間由若干個空格隔開,一行的開始和結(jié)束都沒有空格。
#include
#include
#define N 80
int fun(char *s)
{
}
main()
{
char line[N];
int num=0;
FILE *out;
char *test[] = {"Hello World!", "This is a test string.", "a b", "cde f g,sf l"};
printf("Enter a string :\n");
gets(line);
num=fun( line );
printf("The number of word is : %d\n\n",num);
out=fopen("out.dat", "w");
for(num=0;num<4;num++)
printf(out, "%d\n", fun(test[num]));
fclose(out);
}