Originally Posted by
Pole
Thank you for the suggestion. However, it does not seem to work on my PC.
No, because your code is wrong. The message array should be global, and here,
Originally Posted by
Pole
Code:
printf("The text is %s", message[MSG_INTRO][LANGUAGES]);
your latter index (LANGUAGES) is out of bounds. Remember, in C indexes start at 0, and reach up to and including SIZE-1.
Here is a fixed example:
Code:
#include <stdlib.h>
#include <stdio.h>
#define LANG_EN 0
#define LANG_PL 1
#define LANG_COUNT 2
static const char *const message[][LANG_COUNT] = {
#define MSG_INTRO 0
/* 0 */ { "Hello", "Witamy" },
#define MSG_MENU1 1
/* 1 */ { "Option1", "Opcja1" },
#define MSG_MENU2 2
/* 2 */ { "Option2", "Opcja2" },
#define MSG_COUNT 3
};
int main(void)
{
printf("message[MSG_INTRO][LANG_EN] = \"%s\"\n", message[MSG_INTRO][LANG_EN]);
printf("message[MSG_MENU2][LANG_PL] = \"%s\"\n", message[MSG_MENU2][LANG_PL]);
return EXIT_SUCCESS;
}
To iterate over all possible messages in each language, use e.g.
Code:
int main(void)
{
int msg, lang;
for (msg = 0; msg < MSG_COUNT; msg++)
for (lang = 0; lang < LANG_COUNT; lang++)
printf("message[%d][%d] = \"%s\"\n", msg, lang, message[msg][lang]);
return EXIT_SUCCESS;
}
instead.