#1
  1. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    47

    How to use German characters like ▀


    I am still working on my German vocab program and it worked very nicely on my Linux machine. :) However, when I compiled it on one of my M$ Windoze machines, it doesn't display German characters such as ▀. Instead, they show up as blocks.

    I did some research and found that since these characters were greater than some value, you have to do something like char indexing or something. It sounds like what I need, but have no idea how to do it. Isn't there an easy way to just change/add a charset? Thanks!
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,642
    Rep Power
    4247
    You'll need to define the _UNICODE symbol for the project and declare all your char variables as TCHAR and your string constants with _T.
    http://msdn.microsoft.com/library/de...e_and_mbcs.asp
    http://msdn.microsoft.com/library/de...n_tchar..h.asp

    Happy reading :)
    Last edited by Scorpions4ever; September 26th, 2003 at 06:07 PM.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jan 2002
    Location
    Seattle WA
    Posts
    863
    Rep Power
    14
    Well, you don't necessarily need to use the T defines if you know you know you're going to need to always use wide characters. You could just stick to wchar_t and preface string constants with L.

    That said, using the T defines are always a good idea in window since it allows on the fly chaning from ascii to unicode with a single #define statement.
  6. #4
  7. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    47
    Hey thanks for the pointers. Here is my code:
    Code:
      #define _UNICODE, _tcsrev;
    
      // So that we can use German characters
      _TCHAR *chRet, ch[50], *chinRet, chin[50];
    
      ch = _tcsrev(chRet);
      chin = _tcsrev(chinRet);
    On compile, it says "lvalue expected," and "Value of expression is not used," and it points to these two lines:

    ch = _tcsrev(chRet);
    chin = _tcsrev(chinRet);

    ??
  8. #5
  9. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,184
    Rep Power
    2222
    I just now read where _tcs* has functions very much like str*. So instead of strcpy,you would use _tcscpy and instead of strcmp you would use _tcscmp.

    So if I interpret it correctly, I believe that your code should read something like:
    Code:
     #define _UNICODE, _tcsrev;
    
      // So that we can use German characters
      _TCHAR *chRet, ch[50], *chinRet, chin[50];
    
      _tcscpy(ch,_tcsrev(chRet));
      _tcscpy(chin, _tcsrev(chinRet));
    The reason you got lvalue errors is because you cannot assign a single value to an entire array. An lvalue (C grammar purists are about to descend upon me for this) is a variable that can receive the rvalue, which is what the stuff to the right of the assignment operator (=) is. So a constant cannot be an lvalue (from "left value" because it's on the left of the assignment), nor can a struct, nor can an array, etc. Only something that can store the value that the rvalue evaluates to. Some languages allow you to assign to a substring, so they would consider a substring to be an lvalue.
  10. #6
  11. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    47
    Thank you! I changed all the functions to _tcs instead of str, and it compiled, but now it's doing what it used to. I have attached an image of where I typed "flei▀ig" and it says it's wrong and displays it from the text file.

    I didn't want to have to paste all my code again, I just don't know what I am doing... I have no idea as to how this UNICODE thing works... :( Thanks for all ya'lls help! I can't do this stuff without such a great community. :)
    Code:
    #include <direct.h>
    #include <iostream.h>
    #include <string.h>
    #include <stdlib.h>
    #include <fstream.h>
    #include <tchar.h>
    
    #define _UNICODE;
    
    int ask_again(_TCHAR question[50], _TCHAR answer[50]);
    
    int main()
    {
      system("cls");
    
      #define _UNICODE;
    
      // So that we can use German characters
      _TCHAR ch[50], chin[50];
    
      char user[50];
      int select_vocab;
      char vocab_file[50], temp;
    
      // Set the default file name.
      _tcscpy(vocab_file, "german_vocab_char.txt");
    
      cout<<"+------------------------------------------+\n";
      cout<<"+---------- | Ich Lerne Deustch |----------+\n";
      cout<<"+------------ | By Sam Powers |------------+\n";
      cout<<"+------------------------------------------+\n";
    
      cout<<"| PLEASE SELECT A VOCAB FILE:              |\n";
      cout<<"|                                          |\n";
      cout<<"| 1) Characteristics                       |\n";
      cout<<"| 2) Nouns                                 |\n";
      cout<<"| 3) Verbs                                 |\n";
      cout<<"| 4) Personal/Interrogative Pronouns       |\n";
      cout<<"| 5) Other                                 |\n";
      cout<<"|                                          |\n";
      cout<<"| ()> ";
     
      cin>>select_vocab;
      temp = cin.get();
    
      cout<<"+------------------------------------------+\n";
     
      if (select_vocab == 1)
      {
        _tcscpy(vocab_file,"german_vocab_char.txt");
      }
      else if (select_vocab == 2)
      {
        _tcscpy(vocab_file,"german_vocab_nouns.txt");
      }
      else if (select_vocab == 3)
      {
        _tcscpy(vocab_file,"german_vocab_verbs.txt");
      }
      else if (select_vocab == 4)
      {
        _tcscpy(vocab_file,"german_vocab_pronouns.txt");
      }
      else if (select_vocab == 5)
      {
        cout<<"| Please enter the text file name that     |\n"
            <<"| contains the vocab, i.e words.txt,       |\n"
            <<"| or vocab.txt: "; 
        cin>>vocab_file;
        cout<<"+------------------------------------------+\n";
      }
      else
      {
        _tcscpy(vocab_file, "german_vocab_char.txt");
      } 
    
      char cur_dir[50];
      // Get the current working dir.
       if( _getcwd( cur_dir, _MAX_PATH ) == NULL )
          perror( "_getcwd error" );
    
      char voc_add[50] = "\\vocab\\";
      _tcscat(cur_dir, voc_add);
    
      _tcscat(cur_dir, vocab_file);
    
      system("cls");
    
      cout<<"+------------------------------------------+\n";
      cout<<"| Opening "<<cur_dir<<"...\n";
      cout<<"| Erfolg!\n";
      cout<<"+------------------------------------------+\n";
      ifstream OpenFile(cur_dir);
     
      if (!OpenFile)
      {
        cout<<"| I was unable to open that vocab file.    |\n";
        cout<<"| Please re-run the program to try again.  |\n";
        cout<<"+------------------------------------------+\n";
        system("pause");
        exit(1);
      }
     
      while(!OpenFile.eof())
      {
        OpenFile.getline(ch,50,'\t');
    
        if ( !_tcscmp(ch, "") )
        {
          system("pause");
          exit(1);
        }
    
        cout<<"| "<<ch<<": ";
        OpenFile.getline(chin,50,'\n');
    
        cin.getline(user, 50);
    
        if ( !_tcscmp(user, "quit") )
        {
          exit(1);
        }
    
        if( !_tcscmp( user, _T(chin) ) )
        {
          cout<<"| Ja, Voll! Das ist richtig!               |\n";
        }
        else
        {
          cout<<"| NINE, NINE!   "<<chin<<"\n";
          ask_again(ch, chin);
        }
        cout<<"+------------------------------------------+\n";
      }
      OpenFile.close();
    
      cout<<"\n\n\n";
    
      return 0;
    }
    
    int ask_again(_TCHAR question[50], _TCHAR answer[50])
    {
      static char user[50];
      
      cout<<"| "<<question<<": ";
    
      cin.getline(user, 50);
    
      if ( !question )
      {
        system("pause");
        exit(1);
      }
    
      if ( !_tcscmp(user, "quit") )
      {
        exit(1);
      }
    
      if( !_tcscmp(user, answer) )
      {
        cout<<"| Ja, Voll! Das ist richtig!               |\n";
        return 0;
      }
      else
      {
        cout<<"| NINE, NINE!   "<<answer<<"\n";
        ask_again(question, answer);
        return 0;
      }
    }
    Attached Images
  12. #7
  13. Happy Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2001
    Location
    UK (University of Kentucky)
    Posts
    1,809
    Rep Power
    47
    So I found this page: http://www.cplusplus.com/doc/papers/ascii.html

    And if you scroll down to the OEM and ANSI charts, where ▀ should be on the OEM chart there is a block just like the one in the program. Also the ń shows up as the weird "E" on the OEM chart. So I made sure my text file was saved as ANSI, and it was. I also used the -A flag on compile to "Enforce strict compliance with ANSI C."

    Does anyone know why when it pulls the text from the file, it pulls it as OEM and not ANSI? This thing is driving me crazy :(

IMN logo majestic logo threadwatch logo seochat tools logo