delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2007/03/07/12:02:45

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
Message-ID: <45EEEB0C.2070109@mainstreetsoftworks.com>
Date: Wed, 07 Mar 2007 11:40:44 -0500
From: Brad House <brad AT mainstreetsoftworks DOT com>
User-Agent: Thunderbird 1.5.0.9 (X11/20070129)
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: line feed
References: <c29 DOT f754a8b DOT 33203d1b AT aol DOT com>
In-Reply-To: <c29.f754a8b.33203d1b@aol.com>
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019