C Programming Tutorial

 
 
 
 

Image

#include <stdio.h>
#include <conio.h>
void main(){
     char s[50],ch;
     int i,c=0;
     clrscr();
     printf(\"Enter any string : \");
     for(i=0;ch!=\'\\n\';i++){
     ch=getchar();
     s[i]=ch;
     }
     s[i]=\'\\0\';

     for(i=0;s[i]!=\'\\0\';i++){
    if(s[i]==\' \'){
       c++;
       while(s[i]==\' \')
        i++;
    }
     }
     printf(\"\\n\\nTotal words are %d\",c+1);
     getch();
}

 
 
Didn't find what you were looking for? Find more on Program that counts number of words in a given string......