www.digitalmars.com         C & C++   DMDScript  

c++.dos - problem with printf output of carriage return (\r)

reply "Digital Mars C/C++ Compiler" <Ajax4Hire8C hotmail.com> writes:
I have legacy code from Borland C++ v5.xx that usese
the format:

printf("\n\rheader of information\n\r");
while(ok) {
    printf(\r%6i itterations", ii++);
...
}

I get a CR/LF for the \r output.
Instead of a CR only.

Using DMC v8.29n "-mtd" compile to .com option.

Any help appreciated

ajax4hire8c hotmail.com
Oct 21 2002
parent reply "Walter" <walter digitalmars.com> writes:
Looks like you need to set stdout to binary, not text, mode. Try:
    stdout->_flag |= _F_BIN;

"Digital Mars C/C++ Compiler" <Ajax4Hire8C hotmail.com> wrote in message
news:ap0mo4$ok5$1 digitaldaemon.com...
 I have legacy code from Borland C++ v5.xx that usese
 the format:

 printf("\n\rheader of information\n\r");
 while(ok) {
     printf(\r%6i itterations", ii++);
 ...
 }

 I get a CR/LF for the \r output.
 Instead of a CR only.

 Using DMC v8.29n "-mtd" compile to .com option.

 Any help appreciated

 ajax4hire8c hotmail.com
Oct 21 2002
parent "Ajax4Hire8C hotmail" <Ajax4Hire8C hotmail.com> writes:
problem in coding.
ran simple test to confirm both LF & CR/LF output.
worked as expected.

re-examined original code.
I was outputing a line >80 characters so line would wrap to newline.
re-worked the printf to output less than 80 characters, expected output.

Thanks for the quick response.

details of printf and change..
    printf("\r%7s%9s %6u  %-64s"    , cItemREF, cItemSAN, iItemNum,
cItemDes); }
changed to:
    printf("\r%7s%9s %6u  %-32.32s"    , cItemREF, cItemSAN, iItemNum,
cItemDes); }

original printf sent space-padded text beyond column 80; force stdio to wrap
to newline.
corrected printf limits the line to less than 80 to get expected results.

"Walter" <walter digitalmars.com> wrote in message
news:ap17t0$1buv$1 digitaldaemon.com...
 Looks like you need to set stdout to binary, not text, mode. Try:
     stdout->_flag |= _F_BIN;

 "Digital Mars C/C++ Compiler" <Ajax4Hire8C hotmail.com> wrote in message
 news:ap0mo4$ok5$1 digitaldaemon.com...
 I have legacy code from Borland C++ v5.xx that usese
 the format:

 printf("\n\rheader of information\n\r");
 while(ok) {
     printf(\r%6i itterations", ii++);
 ...
 }

 I get a CR/LF for the \r output.
 Instead of a CR only.

 Using DMC v8.29n "-mtd" compile to .com option.

 Any help appreciated

 ajax4hire8c hotmail.com
Oct 21 2002