#include<stdio.h>
#include<conio.h>
void main()
{
int i,words=1;
char str[100];
clrscr();
printf(“Enter a string:”);
gets(str);
for(i=0;str[i]!=’’;++i)
if(str[i]==’ ‘)
words++;
printf(“No. of words are %d”,words);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,words=1;
char str[100];
clrscr();
printf(“Enter a string:”);
gets(str);
for(i=0;str[i]!=’’;++i)
if(str[i]==’ ‘)
words++;
printf(“ No. of words are %d”,words);
getch();
}
翻译自: https://www.thecrazyprogrammer.com/2013/06/c-program-to-count-number-of-words-in.html