warning on wprintf

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...

  1. #1
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675

    warning on wprintf

    problem solved code removed

    Solution : bypass wprintf by using mbstowcs and then printf
    Last edited by std10093; 10-08-2012 at 04:35 PM.

  2. #2
    qny
    qny is offline
    Registered User
    Join Date
    Sep 2012
    Posts
    355
    Try for example
    Code:
    wprintf(L"%d: %s\n", words[i].freq, s);
    //      ^ L for wchar_t string

  3. #3
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Quote Originally Posted by qny View Post
    Try for example
    Code:
    wprintf(L"%d: %s\n", words[i].freq, s);
    I hadn't the L so this might be it,but already bypassed it

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,279
    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.

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    Not my code and i do not like it,but ok,i'll edit

  6. #6
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,675
    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wprintf wchar, always get "?"
    By johnifanx98 in forum C Programming
    Replies: 7
    Last Post: 03-05-2012, 07:47 AM
  2. Replies: 4
    Last Post: 03-12-2011, 05:59 PM
  3. Replies: 9
    Last Post: 05-28-2010, 10:11 AM
  4. New warning in gcc-4.0
    By itsme86 in forum C Programming
    Replies: 1
    Last Post: 04-22-2005, 03:13 PM
  5. gets warning on gcc
    By gsoft in forum C Programming
    Replies: 9
    Last Post: 12-15-2004, 08:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21