Can not so post here
Code:
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <wchar.h>
#include <locale.h>
typedef struct {
wchar_t term[10];
int freq;
} word_t;
/* global array of words */
word_t words[5000];
int n_words = 0;
int find_word(wchar_t s[]) {
int i;
for (i=0; i < n_words; i++)
if ((wcslen(s) == wcslen(words[i].term)) && wcsncmp(s, words[i].term,10) == 0)
return i;
return -1;
}
void add_word(wchar_t s[]) {
assert(wcslen(s) <= 10);
wcsncpy(words[n_words].term, s,10);
words[n_words].freq = 1;
n_words++;
}
int main(void) {
wchar_t s[11];
wint_t c;
int i;
int counter = 0 ;/*use in inserting characters in s*/
setlocale(LC_CTYPE,"UTF-8");
printf("Please type a word with 10 characters at most\n");
while (( c = getwchar() ) != WEOF) {
if( counter > 10 )
{
printf("Word with more than 10 characters detected,so exiting...\n");
return -1;
}
if( c != '\n' )
{
s[counter++] = c;
}
else
{
i = find_word(s);
if (i == -1)
{
add_word(s);
/*wprintf(L"1: %0.10ls\n", s);*/
}
else
{
words[i].freq++;
/*wprintf(L"%d: %0.10ls\n", words[i].freq, s);*/
}
for( i = 0 ; i < 11 i++)/*clear the buffer*/
{
s[i] = '\0';
}
counter = 0;/*reset counter*/
printf("Please type a word with 10 characters at most\n");
}
}
for( i = 0 ; i < n_words ; i++)
{
wprintf(L"%d: %0.10ls\n", words[i].freq, words[i].term);
}
return 0;
}