Mail Archives: djgpp/2007/03/07/12:02:45
Sterten AT aol DOT com wrote:
>
> on this computer in my C-programs
> printf("%c",10);
> prints ascii 13 and ascii 10.
>
> While on another computer it only printed acii 10
> and I used print("%c%c",13,10) for the above purpose.
>
> But that means, the old programs no longer work correctly ?!?
>
> Is it possible to check the system and then branch to
> whatever suitable to print , so the programs work universally ?
First of all, in C, you have handy escape codes,
use '\r' for 13 and '\n' for 10, so you don't have
to use printf format codes.
Next, you can do something like this:
#if defined(_WIN32) || defined(__DJGPP__)
# define NEWLINE "\r\n"
#else
# define NEWLINE "\n"
#endif
printf("Hello World" NEWLINE);
And get the proper behavior on your expected systems.
And yes, there should NOT be a comma between
"Hello world" and NEWLINE as C allows
"H" "e" "l" "l" "o" " " "W" "o" "r" "l" "d"
to be equivalent to
"Hello World"
- Raw text -