통계 단어 수 c 알고리즘
- /* */
- #include <stdio.h>
- #include <string.h>
-
- #define MAX_STRING 200 /* */
-
- int main(void) {
- char str[MAX_STRING] = { 0 }; /* str, 0 */
- int i = 0;
- int length = 0;
- int count = 0;
-
- /* */
- printf("Input original String:");
- gets(str); /* str */
-
- length = strlen(str); /* str */
-
- /* */
- for (i = 0; i < length; ++i) {
- if (str[i] != ' ') { /* */
- ++count;
- while (' ' != str[i] && '\0' != str[i]) /* */
- ++i;
- }
- }
-
- printf("There are %d words in \"%s\".
", /* */
- count, str);
-
- return 0;
- }