잘 안짜지네요 도와주세요~
낶아
파일에서 단어를 읽어서 각 단어가 얼마나 나왔는지 세는 프로그램인데
여기서 단어들 중에 은, 는, 이, 가 , !, .과 같은 필요없는것들은 제외시키는 것입니다.
문장을 하나의 단어로 나누어서 비교해서 지워야될거 같은데 잘 안되네요
도와주세요~
#include string.h
#include stdio.h
typedef struct WORDCOUNT
{
char word[20];
int count;
} WORDCOUNT;
#define MAX_WORDS 200
void AddWord(WORDCOUNT words[], int* size, char* token);
void ShowWord(WORDCOUNT words[], int size);
int main()
{
WORDCOUNT words[MAX_WORDS];
int count = 0;
char str[100];
FILE* file = fopen(test.txt, rt);
if ( file == NULL )
{
printf(file open error!\n);
return 1;
}
fscanf(file, %s, str);
while ( !feof(file) )
{
AddWord(words, &count, str);
fscanf(file, %s, str);
}
fclose(file);
printf(토큰:\n);
ShowWord(words, count);
return 0;
}
void ShowWord(WORDCOUNT words[], int size)
{
int i;
for ( i = 0; i size; ++i )
printf(%s(%d)\n, words[i].word, words[i].count);
}
void AddWord(WORDCOUNT words[], int* size, char* token)
{
int i;
for ( i = 0; i *size; ++i )
{
if ( strcmp(words[i].word, token) == 0 )
{
++( words[i].count );
return;
}
}
if ( *size == MAX_WORDS - 1 )
return;
strcpy(words[*size].word, token);
words[*size].count = 1;
++(*size);
}