discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Preserving newlines


From: Nate Smith
Subject: Preserving newlines
Date: Thu, 08 Jun 2006 11:57:22 -0400

Hello,

In my application I read in a c-string, convert that c-string to an
NSString, and then print that NSString using printf. If I input a
newline character into the c-string, when I print the NSString, it
prints out the '\n' character, instead of a newline. Here's the code (I
don't really use scanf or a finite-length char like this in the real
code!!):

char cInput[1000];
scanf( "%s", cInput );
NSString *input = [ NSString stringWithCString: cInput encoding:
NSNonLossyASCIIStringEncoding ];
printf( "output: |%s|\n", [ input cStringUsingEncoding:
NSNonLossyASCIIStringEncoding ] );


So when I run it, and enter in:
Hi\n

It prints out:
output: |Hi\n|

but I want it to print out:
output: |Hi
|

I could always manually parse the output, and if a "\n" is found, then
really print a newline, but that seems a bit too muddled. Any ideas?
Thanks

Nate






reply via email to

[Prev in Thread] Current Thread [Next in Thread]