글

라벨이 C인 게시물 표시

[C] C언어, 구조체_단어빈도수 세기 프로그램

 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<string.h> #include<ctype.h> #define NSIZE 1000 struct symtab { char sym[20]; int count; }; int searchword(struct symtab tbl[], int size, char word[]); int getword(char s[]); int main(void) { struct symtab table[NSIZE]; int longstring = 0; int n = 0; char s[80]; int i; for (i = 0; i < NSIZE; i++) { table[i].count = 0; } while (getword(s)) { if (strlen(s) >= 20) { longstring++; continue; } i = searchword(table, n, s); if (i < 0) { if (n >= NSIZE) { printf("no size with symbol table"); break; } i = n++; strcpy(table[i].sym, s); } table[i].count++; } for (i = 0; i < n; i++) { printf("$-20s: %d\n", table[i].sym, table[i].count); } printf("%-20s: %d\n", "길이 20이상의 단어", longstring); return 0; } //단어 탐색 함수 int searchword(struct symtab tbl[], int size, char word[]) { int i; ...