Skip to content

Instantly share code, notes, and snippets.

@ThePratikSah
Created July 25, 2017 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThePratikSah/9db858c3d385dcf35505203c3fbd3788 to your computer and use it in GitHub Desktop.
Save ThePratikSah/9db858c3d385dcf35505203c3fbd3788 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
int main(){
char str[40];
int i, word = 1;
printf("Enter a sentence:\n");
scanf("%[^\n]s", str);
for( i = 0 ; str[i] != '\0' ; ++i){
if(str[i] == ' ')
word++;
}
printf("Number of words = %d", word);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment