Thread: Output Polish Language Chars

  1. #1
    diligentStudent()
    Join Date
    Apr 2002
    Posts
    79

    Output Polish Language Chars

    Hi. I am trying to write a program that outputs Polish language characters to the ms-dos console, but am running into trouble. Evidently, I have to use something outside the 256 ascii character-set. Can anyone point me in a helpful direction? Thanks, Steve

  2. #2
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    For console based programs you are going to need to get into what is called code pages. A code page defines a mapping of of character codes to to characters. These are set up so the lower 128 characters are the standard ASCII characters whereas the higher 128 codes depend on the language of the code page.

    To do this for console programming you will need to ensure the code page is installed on your system. It is located here:

    HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Contro l\Nls\CodePage

    in the registry.

    If you have the code page installed on your system you can set console input by using

    Code:
    BOOL SetConsoleCP( UINT wCodePageID)
    where wCodePageID is one of the registry entries contained above.

    Code:
    BOOL SetConsoleOutputCP( UINT wCodepageID)
    these files are located in windows.h and you read up on them at
    MSDN

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    I'm not sure it would work under MS-DOS, but if anyone with a similar problem is using different platforums, Unicode is another option. It's a character set that is probably one of the most universal in common usage. Java uses it, and it's been implemented in .NET.

    edit: As for the above post, if it's true MS-DOS and not just a console window, I'm not so sure about all the registry stuff...
    Last edited by sean; 12-24-2004 at 06:10 PM.

  4. #4
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    UNICODE does solve all these problems however I do believe (however I am not sure) that it wasn't designed for use with console programs.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well you'd just need to get an API that works in DOS. They're out there for just about every platform.

  6. #6
    Handy Andy andyhunter's Avatar
    Join Date
    Dec 2004
    Posts
    540
    That would be what I posted above.
    Last edited by andyhunter; 12-24-2004 at 06:47 PM.

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Outputting unicode characters to the windows console is a bit of a mess. In theory, we should be able to use wprintf or wcout. In reality, these seem to be unreliable at best and probably totally broken. Fortunately, the native windows functions seem to work fine.

    Here is a sample program. It requires MSVC.NET and the source must be saved as unicode. Dev-C++ will not compile unicode source files, so for that compiler, some alterations must be made.
    Code:
    #include <windows.h>
    #include <stdio.h>
    #include <iostream>
    #include <strsafe.h>
    using namespace std;
    
    /*
     * Version of wprintf that uses windows functions
     */
    DWORD win_wprintf(LPCWSTR szFormat, ...)
    {
    #       ifndef ARRAY_SIZE
    #         define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
    #       endif
    
    	WCHAR   szText[1024 * 10];
    	va_list args;
    	DWORD   dwWritten;
     
    	/* Format the text into the buffer */
    	va_start(args, szFormat);
    	StringCchVPrintfW(szText, ARRAY_SIZE(szText), szFormat, args);
    	va_end(args);
     
    	/* Output the buffer to the console. */
    	if (WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), szText, lstrlenW(szText), &dwWritten, NULL))
    	{
    		return dwWritten;
    	}
    
    	return 0;
    }
    
    
    int main(void)
    {
    	printf("Before continuing make sure the console font is set to 'Lucida Console'\n");
    	getchar();
    
    	/* Try with the C std library. */
    	wprintf(L"ęŃźŚłŁĘĄĆŻżĶaz09!> %s\n", L"Ććķ");
    
    	/* Try with the C++ std library. */
    	wcout << L"ęŃźŚłŁĘĄĆŻżĶaz09!> " << L"Ććķ" << endl;
    
    	/* Try with the windows replacement. */
    	win_wprintf(L"ęŃźŚłŁĘĄĆŻżĶaz09!> %s\n", L"Ććķ");
    
    	getchar();
    }
    In my testing, wprintf and wcout output nothing while win_wprintf gives the correct result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. Problem with my reverse function and its output!
    By Matus in forum C Programming
    Replies: 4
    Last Post: 04-29-2008, 08:33 PM
  4. Trying to store system(command) Output
    By punxworm in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2005, 06:46 PM
  5. Output problems with structures
    By Gkitty in forum C Programming
    Replies: 1
    Last Post: 12-16-2002, 05:27 AM