Thread: French characters not displaying on MS DOS Window

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    27

    French characters not displaying on MS DOS Window

    Hi,

    I've tried searching for the answer, so please direct me links if I have been unsuccessful.

    I have a function that reads in characters and displays a frequency of them, here is an output from DOS:

    Code:
            Letter | Frequency
            --------------------
            A      | 7
            B      | 2
            C      | 10
            D      | 1
            E      | 6
            F      | 4
            I      | 11
            J      | 7
            L      | 4
            M      | 4
            N      | 1
            P      | 4
            Q      | 2
            R      | 6
            S      | 11
            U      | 1
            V      | 1
            a      | 272
            b      | 16
            c      | 106
            d      | 108
            e      | 431
            f      | 40
            g      | 33
            h      | 23
            i      | 244
            j      | 17
            k      | 1
            l      | 164
            m      | 92
            n      | 225
            o      | 150
            p      | 85
            q      | 38
            r      | 208
            s      | 268
            t      | 194
            u      | 159
            v      | 32
            x      | 9
            y      | 4
            z      | 1
            Ó      | 10
            þ      | 2
            Þ      | 9
            Ú      | 97
            Û      | 2
            ´      | 1
            ¶      | 2
            ¹      | 1
    
    Press any key to continue
    Now the last characters are french ones such as "é" this shows up as "Ú" on the table above . So how can I change my display setting to get DOS to display the correct characters?

    Thank you in advance.
    CookieMonster

  2. #2
    Registered User
    Join Date
    Dec 2003
    Posts
    53
    Err... I'm not too sure that's possible?
    Normally, when we play with characters in console, we are using the ascii character set...
    now, without the windows.h header file, I'm not aware of any way of outputing unicode characters, which I think you'll need in order to print out those characters

    However, that doesn't mean that it's impossible, cause I've seen my console switch to what I would presume to be unicode when I play with my language settings in windows...

    Dig deep enough into the windows functions and you might find a way...
    here's a link to the MSDN database...
    http://msdn.microsoft.com/library/en..._functions.asp
    Watdaya know! I just managed to hit on the correct sequence of clicks to get what you need in order to do that!
    http://msdn.microsoft.com/library/en...tconsolecp.asp
    this function SetConsoleCp should just do the trick! You will have to do a bit of digging around your computer's registry tho...
    And I believe you only have to set it to enlish codepage...
    Last edited by tzuchan; 04-03-2004 at 05:16 PM.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You could also try changing the code page on the command line with mode
    Code:
     c:>mode /?
     
     Configures system devices.
     
     Serial port:       MODE COMm[:] [BAUD=b] [PARITY=p] [DATA=d] [STOP=s]
                                     [to=on|off] [xon=on|off] [odsr=on|off]
                                     [octs=on|off] [dtr=on|off|hs]
                                     [rts=on|off|hs|tg] [idsr=on|off]
     
     Device Status:     MODE [device] [/STATUS]
     
     Redirect printing: MODE LPTn[:]=COMm[:]
     
     Select code page:  MODE CON[:] CP SELECT=yyy
     
     Code page status:  MODE CON[:] CP [/STATUS]
     
     Display mode:      MODE CON[:] [COLS=c] [LINES=n]
     
     Typematic rate:    MODE CON[:] [RATE=r DELAY=d]
    Code:
     c:>mode con
     Status for device CON:
     ----------------------
     	Lines:		  300
     	Columns:		80
     	Keyboard rate:  31
     	Keyboard delay: 1
     	Code page:	  437
    Or you could use the chcp command:
    Code:
     Displays or sets the active code page number.
     
     CHCP [nnn]
     
       nnn   Specifies a code page number.
     
     Type CHCP without a parameter to display the active code page number.
    http://www.microsoft.com/resources/d...n-us/chcp.mspx
    http://www.microsoft.com/resources/d...us/ntcmds.mspx

    But then again, if you've a French PC, I guess you should already have the CP set properly?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Well, I was going to provide an answer, but then I found a google search that produced an interesting result instead.

    http://www.google.com/search?q=outpu...aracter+printf

    I'd look especially hard at result number 2.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    HighFlyer is me!

    Over there I was unable to find an answer for the malloc thing, so I came here. Hope there is nothing wrong in doing that, is there?

    I'm still searching into the French character display thing from the links.

    Hammer: Are there any risks in chaing my system configurations like you have shown?
    Last edited by CookieMonster; 04-04-2004 at 02:46 PM. Reason: typo

  6. #6
    Registered User
    Join Date
    Feb 2004
    Posts
    73
    out of curiousity, could i see the code for that function cookiemonster?

  7. #7
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    Here it is, my original! (I warn you, this maybe a little long winded, but I've only been learning c for about... 6 months, but it works like a dream apart from displaying the french characters!):

    PS: R u comparing your version you've done bfore to mine?? Well, you win, I garantee it.

    Code:
    void letterfrequencies (char *location)
    {
    
    	printf("\n\n\tLetter | Frequency");
    	  printf("\n\t--------------------");
    
    	int n,freq[256];
    	int count=0;	
    	FILE *text;
    
    	for (n = 0; n <= 255; n++)
        freq[n] = 0;
    
    	text=fopen(location,"r");
    
        char * string;
        size_t string_size;
        string_size = totalcharacters(location);
        string = (char *) malloc(string_size); //Makes sure that the length of a word cannot be greater than the number of characters in the file!
    
    	unsigned char ch;
    	while((fgets (string, string_size, text)) != NULL)
    	{
    		for(count=0;(string[count]!=NULL);count++)
    		{
    			ch = (unsigned char) string[count];
    			if ((ch>='\0')&&(ch<='?')) ; //only filters letters of words characters
    			else
    			{
    				freq[ch]++;
    			}
    		}
    	}
    
    	for(n=0;n<=255;n++)
    	{
    		if (freq[n]!=0)
    			printf("\n\t%c      | %i",n,freq[n]);
    		else
    			; //do nothing
    	}
    //do printf statements of description of charcters that DOS displays wrong if unable to reslove the frenchy charter problem
    		fclose (text);
    }
    Last edited by CookieMonster; 04-04-2004 at 03:07 PM. Reason: PS

  8. #8
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    I changed the DOS code page:

    Code:
    C:\Documents and Settings>chcp 863
    Active code page: 863
    
    C:\Documents and Settings>mode con codepage /status
    
    Status for device CON:
    ----------------------
        Code page:      863
    But it still doesn't seem to work... little more play around with the numebrs I shall try...
    Last edited by CookieMonster; 04-04-2004 at 03:51 PM. Reason: console DOS

  9. #9
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    Here is why it's not working:

    Code:
    Microsoft Windows XP [Version 5.1.2600]
    (C) Copyright 1985-2001 Microsoft Corp.
    
    C:\Documents and Settings\>mode con codepage /status
    
    Status for device CON:
    ----------------------
        Code page:      850
    The codepage changes back to 850 for some reason?

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Each new command window starts afresh I'm afraid.

    If you want to set the CP in your program, try these (already posted above)
    http://msdn.microsoft.com/library/de...tconsolecp.asp
    http://msdn.microsoft.com/library/en...leoutputcp.asp
    http://msdn.microsoft.com/library/en...leoutputcp.asp

    But before you go messing around with those, does the program work as you want if you manually set the CP?
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    Quote Originally Posted by tzuchan
    http://msdn.microsoft.com/library/en...tconsolecp.asp
    this function SetConsoleCp should just do the trick! You will have to do a bit of digging around your computer's registry tho...
    I don't think I have the right idea in using this function, it asks for the headers and so here is what I wrote on my program:

    Code:
    #include <wincon.h>
    #include <windows.h>
    BOOL SetConsoleCP(UINT 863); //to display the french characters
    Which compiles with 83 errors.

    What do you mean by "You will have to do a bit of digging around your computer's registry tho..." ? I bet this relates to this
    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Nls\CodePage registry

    But what does all this mean? Where can I learn to change my computers registry?

    Also, I tried using the commands

    Code:
    mode device codepage select=yyy
    
    mode device codepage [/status]
    However, as the new DOS window comes up when I execute my program, this codepage change is lost and when I check the status it goes back to the code 850, my default setting.

  12. #12
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    Quote Originally Posted by Hammer
    Each new command window starts afresh I'm afraid.

    If you want to set the CP in your program, try these (already posted above)
    http://msdn.microsoft.com/library/de...tconsolecp.asp
    http://msdn.microsoft.com/library/en...leoutputcp.asp
    http://msdn.microsoft.com/library/en...leoutputcp.asp
    I read all of these. Everytime I use them I get about 83 compiler erros. I'm not too sure how to use them.

    Quote Originally Posted by Hammer
    But before you go messing around with those, does the program work as you want if you manually set the CP?
    Continue please, do you mean setting the CP and then executing my program in the opened DOS window? I'll give it a try.

  13. #13
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>However, as the new DOS window comes up when I execute my program
    Start a console window via Start->Run->cmd (or whatever you need to do), then CD your way to your program's directory. Change the CP, then run your program by typing its name on the command line. Does it give you what you want?

    [edit]
    Our posts must have just missed each other... yes, give this a go before you do any coding work on it.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  14. #14
    Registered User
    Join Date
    Apr 2004
    Posts
    27
    I cd alllll teh way to my .exe file in the debug folder, then here was my output:


    Code:
    Text file called *frencharticle* has the follwing statstics:
    
            ERROR: File Not Found!
    This was cause from this line of the source code:


    Code:
    	printf("\n\nText file called *%s* has the follwing statstics:",name);
    	if (fopen(location,"r")==NULL) printf ("\n\n\tERROR: File Not Found!"); //unknown file will not execute the following table.
    So for some reason my file cannot be opened or located. When I execute my program in Microsoft Visual C++, it works fine.

    Infact when open this .exe file in the debug fodler using normal windows, I get the same Error message printed, then the DOS window closes really quickly. Why doesn't this .exe file work?

    Sooo close, I'm not giving up now!

  15. #15
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Is frencharticle is the current directory? Does it have a file extension (I guess not as it works one way and not another).

    Most likely that file is in another directory.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating a child window
    By rakan in forum Windows Programming
    Replies: 2
    Last Post: 01-23-2007, 03:22 PM
  2. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  3. Adding buttons, edit boxes, etc to the window
    By rainmanddw in forum Windows Programming
    Replies: 1
    Last Post: 04-10-2006, 03:07 PM
  4. my wndProc is out of scope
    By Raison in forum Windows Programming
    Replies: 35
    Last Post: 06-25-2004, 07:23 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM