printf and unsigned char
-
Hi all How can I print unsigned char's to the console? I compile with the "default unsigned char" option as this has to run on Linux, but in Windows it just spits out garbled characters. Thanks :) I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
-
Hi all How can I print unsigned char's to the console? I compile with the "default unsigned char" option as this has to run on Linux, but in Windows it just spits out garbled characters. Thanks :) I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
leppie wrote: How can I print unsigned char's to the console?
unsigned char c = 'A';
printf("%c",c);
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
leppie wrote: How can I print unsigned char's to the console?
unsigned char c = 'A';
printf("%c",c);
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
Thanks Nish, but I'm not sure that will help :confused: I'm reading Afrikaans text from a file. And Afrikaans has all those nice o's, e's, with various thingies on them. Here's some code:
FILE *input;
char inputfile[50] = "input.txt";
char word[50];
char yesno;if ((input = fopen(inputfile, "r")))
{
while (!feof(input))
{
fscanf(input, "%s", word);if (!trieIsMember(word)) { //here the "upper" (128+) chars dont print properly to console //the char are shown properly in the debugger though, no prob in linux printf("Spell Error: %-20s Add word? ", word); yesno = getchar();getchar(); //for enter if (tolower(yesno) == 'y') trieAdd(word); }
}
fclose(input);
}Any ideas? I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
-
leppie wrote: How can I print unsigned char's to the console?
unsigned char c = 'A';
printf("%c",c);
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
OK I found out what the problem is. It appears to be an ANSI/ASCII conflict. The letters appear fine in ANSI charset, but comes out funny in ASCII what it appears they are using for the console. Now the question is: How can I print ANSI strings properly to ASCII? And I thought DOS was dead.... ;P I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
-
Thanks Nish, but I'm not sure that will help :confused: I'm reading Afrikaans text from a file. And Afrikaans has all those nice o's, e's, with various thingies on them. Here's some code:
FILE *input;
char inputfile[50] = "input.txt";
char word[50];
char yesno;if ((input = fopen(inputfile, "r")))
{
while (!feof(input))
{
fscanf(input, "%s", word);if (!trieIsMember(word)) { //here the "upper" (128+) chars dont print properly to console //the char are shown properly in the debugger though, no prob in linux printf("Spell Error: %-20s Add word? ", word); yesno = getchar();getchar(); //for enter if (tolower(yesno) == 'y') trieAdd(word); }
}
fclose(input);
}Any ideas? I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
leppie wrote: I'm reading Afrikaans text from a file That makes a huge difference. Now you basically need wide character versions of all the functions you have been using :-) Replace printf with wprintf, fopen with _wfopen, fscanf with fwscanf etc... Regards, Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
OK I found out what the problem is. It appears to be an ANSI/ASCII conflict. The letters appear fine in ANSI charset, but comes out funny in ASCII what it appears they are using for the console. Now the question is: How can I print ANSI strings properly to ASCII? And I thought DOS was dead.... ;P I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
leppie wrote: Now the question is: How can I print ANSI strings properly to ASCII? Those are wide character strings (using unicode) See my reply to your other post :-) Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
leppie wrote: Now the question is: How can I print ANSI strings properly to ASCII? Those are wide character strings (using unicode) See my reply to your other post :-) Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
I can assure you those are NOT wide. :) These are the ones: ëêéô , but the command prompt just does not spit them out correctly. I get what looks like an epsilon, omega, theta and integral characters, in that order. [edit]δΩΘ⌠ , these are the ones I get on the console[/edit] Perhaps its to do with regional settings...? I will have a look. :) There is an options for codepage for non unicode programs. It was set to English US. I have change this now, but requires a reboot. I have not planned a reboot yet, but perhaps Monday will be a good day. Windows XP has been running 2wks 4days 8hrs 33mins. :eek: I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
-
I can assure you those are NOT wide. :) These are the ones: ëêéô , but the command prompt just does not spit them out correctly. I get what looks like an epsilon, omega, theta and integral characters, in that order. [edit]δΩΘ⌠ , these are the ones I get on the console[/edit] Perhaps its to do with regional settings...? I will have a look. :) There is an options for codepage for non unicode programs. It was set to English US. I have change this now, but requires a reboot. I have not planned a reboot yet, but perhaps Monday will be a good day. Windows XP has been running 2wks 4days 8hrs 33mins. :eek: I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
leppie wrote: I can assure you those are NOT wide. These are the ones: ëêéô Uhm, okay and sorry abt the confusion. I guess the command prompt is simply unable to show those characters by default. The codepage idea sounds good. Good luck. And if you get it to work, write an article for CP ;-) Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
-
leppie wrote: I can assure you those are NOT wide. These are the ones: ëêéô Uhm, okay and sorry abt the confusion. I guess the command prompt is simply unable to show those characters by default. The codepage idea sounds good. Good luck. And if you get it to work, write an article for CP ;-) Nish
Author of the romantic comedy Summer Love and Some more Cricket [New Win] Review by Shog9 Click here for review[NW]
Nishant S wrote: And if you get it to work, write an article for CP I think its rather a bug in XP ;P ë (copied) for example comes up as 235 where by defualt it should be 137 according to the ASCII table.:confused: I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
-
Nishant S wrote: And if you get it to work, write an article for CP I think its rather a bug in XP ;P ë (copied) for example comes up as 235 where by defualt it should be 137 according to the ASCII table.:confused: I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
One possible way to display
unsigned char
inprintf
is to convert it to anint
and display theint
as achar
.int x = 240; printf("%c .. %d\n", x, x);
This will surely be slow for large strings! :~ Hope this helps you someway!:-O Rgds, Nirav:-) * The world stands aside to let anyone pass who knows where he is going! - David Jordan * -
Thanks Nish, but I'm not sure that will help :confused: I'm reading Afrikaans text from a file. And Afrikaans has all those nice o's, e's, with various thingies on them. Here's some code:
FILE *input;
char inputfile[50] = "input.txt";
char word[50];
char yesno;if ((input = fopen(inputfile, "r")))
{
while (!feof(input))
{
fscanf(input, "%s", word);if (!trieIsMember(word)) { //here the "upper" (128+) chars dont print properly to console //the char are shown properly in the debugger though, no prob in linux printf("Spell Error: %-20s Add word? ", word); yesno = getchar();getchar(); //for enter if (tolower(yesno) == 'y') trieAdd(word); }
}
fclose(input);
}Any ideas? I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02