#include <stdio.h> #include <string.h> main(){ char str[50],*p = str,*q; int i,t = 0,n = 0; q = NULL; gets(p); for(i = 0; ; i++){ if(*(p +i) == '\0' ) break; t++; } for(i = 0; i <=t; i++){ if(q == NULL || *q == ' '){ if(*(p+i) != ' ') q = p+i; } else if(*(p+i) == ' ' || *(p+i) == '\0'){ n++; q = p+i; } } printf("%d\n",n); return 0; } |
Double click to view unformatted code.