Translation

This is a discussion on Translation within the C Programming forums, part of the General Programming Boards category; Ok, here's my question: I have an array of char Code: char *Menu[] = {"File", " ", "View"}; My translation ...

  1. #1
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669

    Question Translation

    Ok, here's my question:

    I have an array of char
    Code:
    char *Menu[] = {"File", "   ", "View"};
    My translation function will return a pointer to a char.
    Use of mine translating function will be something like that:

    printf ("%s", Translate(1)); // 1 is not important in this case

    Now If I want to translate the menu options how do I do that in this case, when I have an array of char?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Menu[0] contains "File"
    Menu[1] contains " "
    Menu[2] contains "View"

    ...if I understood your question correctly
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    My question is how to translate the "File" in the array of char. I can't write this:

    Code:
    char *Menu[] = {"%s", "   ", "View"}, Translate(1);
    So how to translate it?
    Last edited by GaPe; 04-03-2002 at 12:57 PM.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    What do you mean by translate? Translate to what? I suppose you don't mean translate into another language .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Yes translate into another question.
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    char* Translate(int Nr)
    {
      return &Menu[Nr];
    }
    This code returns a pointer to the "option-string", "File" if you enter 0, " " if you enter 1 and so on...
    Haven't tried it, but it should work!
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Hmm... forget about translating. I totally messed up my question.
    Ok, I have this:

    Code:
    const char FILE[] = "File1";
    
    char *Menu[] = {"File", "   ", "View"};
    I tried this:
    Code:
    char *Menu[] = {"%s", "   ", "View"}, FILE;
    But it is not working.

    Now, how do I replace "File" with constant FILE?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    > char *Menu[] = {"%s", " ", "View"}, FILE;
    >
    > Now, how do I replace "File" with constant FILE?

    'FILE' is not a constant. 'FILE' here is a single char called 'FILE'.
    You need to explain your question better. No one can figure out
    what the heck you're trying to do.

    If you do what you're doing above with 'Menu', and you assign
    values like this, you can't simply replace them:

    char *Menu[] = { "Want", "to", "see", "a", "memory", "leak?" };

    Menu[3] = "Oops!";

    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by quzah
    char *Menu[] = { "Want", "to", "see", "a", "memory", "leak?" };

    Menu[3] = "Oops!";
    Haha, that's a good one LOL

  10. #10
    Code Warrior
    Join Date
    Nov 2001
    Posts
    669
    Look if I have an array of char there must be some way to change those strings in it. I'm aksing you guys how to change the string in an array of char.

    ------------
    I found a bug in my program. When I have a windowed program then the font is ok, but when I resize my program to full screen than I have a messed font.
    Example:
    - windowed program -> "" // my alphabet (Slovenian language)
    - fullscreen program -> "ߤ" // that is wrong

    And new question is how to write unicode characters for my program?
    Current projects:
    1) User Interface Development Kit (C++)
    2) HTML SDK (C++)
    3) Classes (C++)
    4) INI Editor (Delphi)

  11. #11
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I'm aksing you guys how to change the string in an array of char.
    Use either a multidimensional array, or allocate memory for an array of char pointers and use the string manipulating functions.

    >char *Menu[] = {"File", " ", "View"};
    The array notation here doesn't mean that you can modify the strings, it's the same as:
    char *Menu1 = "File";
    char *Menu2 = " ";
    char *Menu3 = "View";

    Which we all know cannot be modified without bad things happening. Something more like this would work however:
    char *Menu[3];
    Menu[0] = malloc ( sizeof "File" ); /* Don't forget to test malloc */
    strcpy ( Menu[0], "File" );
    etc...

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. character set translation
    By password636 in forum C Programming
    Replies: 1
    Last Post: 06-08-2009, 11:45 AM
  2. How to find relative translation...
    By Shamino in forum Game Programming
    Replies: 5
    Last Post: 05-20-2007, 09:39 PM
  3. Website translation
    By Jumper in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 03-17-2004, 08:34 PM
  4. msvc translation unit
    By Stoned_Coder in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 05-14-2003, 05:31 AM
  5. Replies: 3
    Last Post: 12-03-2002, 09:45 AM

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