I'm struggling to print "ę" in this sentence in C:
...W Katalogu o nazwie "c:\roboczy" znajduje się 90% dobrze napisanych programów w C...
My cmd's encoding page is CP-852 ("Latin 2"). I'm writting in Dev-C++ 5.11 and my compiler is TDM-GCC 4.9.2 64-bit Release.
I've managed to print the backslash and ó using this script:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char znak1 = 92;
printf("...W Katalogu o nazwie %\"c:%croboczy%\" znajduje sie 90%% dobrze napisanych program\242w
w C...\n",znak1);
return 0;
}
Of course right now it's just "e" in there, but neither inserting "\281" directly into the printf nor putting 0x119 into a char like znak1 up there has worked.
For example whith "\281" inserted I get:
...W Katalogu o nazwie "c:\roboczy" znajduje si☻81 90% dobrze napisanych programów w C...
While adding a char variable like znak1 with value 0x119 yields:
...W Katalogu o nazwie "c:\roboczy" znajduje si↓ 90% dobrze napisanych programów w C...
I understand I can simply hold on to ASCII characters and the output will be readable but it bugs me not to be able to do such a simple thing in this language. I'll appreciate some tips on what to do!
Cheers! :)
Even now that you already found a way to reach your goal, I'll explain the result of your try.
For example whith "\281" inserted I get:
...W Katalogu o nazwie "c:\roboczy" znajduje si☻81 90% dobrze napisanych programów w C...
Regardless of how you arrived at the wrong code, 281 is not a valid octal number, since that has only digits from 0 to 7. So only \2
was recognized as an escape sequence for ☻
, and 81
were printed literally.
By the way, instead of inserting the character with printf
and %c
, you can as well directly write the escape sequence into the string, more easily hexadecimal than octal: "… znajduje si\xA9 …"
.