关于C语言 万分火急!!!!

来源:百度知道 编辑:UC知道 时间:2024/09/20 03:21:33
“I love c programming class
word count = 5


• This program read string as a gets function and
store it in an array and check the number of words
use with pointer notation.
• Use word_count function for checking work
count
• Skip blank(‘ ‘)
• gets(string) to read a chracter string.

就是输入字符串,然后计算一共出来了几个单词,用指针符号
我急需要程序的全部内容

#include <stdio.h>
int word_count(char *s)
{
int i,word=0,count=0;
for(i=0;*(s+i)!=0;++i)
{
if(*(s+i)==' ')
word=0;
else
if(word==0)
{
word=1;
++count;
}
}
return count;
}
int main()
{
char s[100];
int count=0;
gets(s);
count=word_count(s);
printf("count = %d\n", count);
return 0;
}

#include<stdio.h>
void main()
{
char string[81],c;
int i,num=0,word=0;
char *p;
gets(string);
for(p=string;*p!='\0';p++)
if(*p==' ') word=0;
else if(word==0)
{
word=1;
num++;
}
printf("there are %d words in the line.\n",num);
}

main()
{int i,s=0;char a[100];
gets(a);
for(i=0;i<strlen(a);i++)
{*p=a;
if(*p==32)
s=s+1;}
print