#include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { char str[1000]; gets(str); int i=0; int sum=0; while(str[i]==' ')i++; while(str[i]) { if(str[i]==' ') { while(str[i+1]==' ')i++; if(str[i+1]&&str[i+1]!=' ') sum++; } i++; } sum++; printf("%d",sum); return 0; } |
Double click to view unformatted code.