#include
"
stdio.h
"
#include " conio.h "
#include " string.h "
int count_words( char str[]);
void main()
{
int n;
char s[80];
clrscr();
printf("Input a string:");
gets(s);
n=count_words(s);
printf("Word number is %d",n);
}
int count_words( char str[])
{
int k,num=0;
k=strlen(str);
do{
k--;
}while(str[k]==' ');
str[k+1]='\0';
k=0;
while(str[k]==' ') k++;
if(str[k]!='\0') num=1;
while(str[k]!='\0')
{
if(k>0 && str[k]==' ' && str[k-1]!=' ')
num++;
k++;
}
return num;
}
#include " conio.h "
#include " string.h "
int count_words( char str[]);
void main()
{
int n;
char s[80];
clrscr();
printf("Input a string:");
gets(s);
n=count_words(s);
printf("Word number is %d",n);
}
int count_words( char str[])
{
int k,num=0;
k=strlen(str);
do{
k--;
}while(str[k]==' ');
str[k+1]='\0';
k=0;
while(str[k]==' ') k++;
if(str[k]!='\0') num=1;
while(str[k]!='\0')
{
if(k>0 && str[k]==' ' && str[k-1]!=' ')
num++;
k++;
}
return num;
}