Hey, I'm trying to write a program that teaches you basic Danish vocabulary. Anyway, I originally had an array of structs with const chars for the dan word and eng word like so...
Code:
struct ord{
char* dan;
char* eng;
}ords[ORDNUMMER];//ORDNUMMER defined earlier
//some other stuff...
ords[4].dan="some danish word";
ords[4].eng="some english word";
//and so on
So, then I came up with this crazy idea... I want to read the values I'm assigning to each const string from a file of hex nummers. Here's the file, called testfire.dat:
61 6c 6d 69 6e 64 65 6c 69 67 65 64 00000000 //Almindeliged
6f 72 64 69 6e 61 72 79 2c 20 6e 6f 72 6d 61 6c 00000000 //Ordinary, normal
61 72 62 65 6a 64 65 00000000 //arbejde
77 6f 72 6b 00000000 //work
62 65 73 c3 b8 67 65 00000000 //besøge
I put C style comments in there so you can see what the values mean. They're not actually in the file. (Also, the 00000000 signifies the end of a word, as you'll see later)
Please note I'm assuming UTF-8 encoding. The problem I'm having is with the last line, the ø character, hex c3 b8. I get a segmentation fault when I run it in the command line. It's interesting, because when I run it in gdb, I don't get a seg fault, but it skips over the last e in besøge:
Running a.out
Code:
webmaster@sWAN:~/Hent/Tests$ ./a.out
almindeliged
ordinary, normal
arbejde
work
Segmentation fault
webmaster@sWAN:~/Hent/Tests$
Running GDB
Code:
(gdb) run
Starting program: /home/webmaster/Downloads/Tests/a.out
almindeliged
ordinary, normal
arbejde
work
besøg
Program exited normally.
(gdb)
Oh! Almost forgot the source...
Code:
for(k=0;k!=6;k++){
do{
fscanf(mFile, "%x", &ords[i].dan[i]);
j=ords[i].dan[i];
printf("%c",ords[i].dan[i]);
i++;
}while(j!=0x00000000);
printf("\n");
}
It may or may not have been obvious, but I honestly don't know a thing about computer memory. So... what's going on?