problem solved code removed
Solution : bypass wprintf by using mbstowcs and then printf![]()
This is a discussion on warning on wprintf within the C Programming forums, part of the General Programming Boards category; problem solved code removed Solution : bypass wprintf by using mbstowcs and then printf...
problem solved code removed
Solution : bypass wprintf by using mbstowcs and then printf![]()
Last edited by std10093; 10-08-2012 at 04:35 PM.
Try for example
Code:wprintf(L"%d: %s\n", words[i].freq, s); // ^ L for wchar_t string
You should know better than to remove code from the original post! This prevents others in the future seeing a similar problem from finding a solution.
Not my code and i do not like it,but ok,i'll edit
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; }