discuss-gnustep
[Top][All Lists]
Advanced

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

Re: scanf does not properly pass characters


From: alex
Subject: Re: scanf does not properly pass characters
Date: Sat, 25 Jan 2014 18:15:29 +0100
User-agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0

Hello,

Here, "NSLog(@"NSString Name is: %s", nameS);"
you are printing an NSString with a plain C format, %s;
You should print that with %@ format.

NSLog(@"NSString Name is: %@", nameS);

Alex (Slex)


On 01/25/14 17:25, igorland wrote:
Markus. Thank you! I have noticed now. Then I faced another issue: converting
the C string to NSString.

Code:

// First program

#import <Foundation/Foundation.h>

int main (int argc, const char* argv[])
{
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

        char nameC[50];
        NSLog(@"ENter your name: ");
        scanf("%s", &nameC);
        NSString* nameS = [NSString stringWithCString:nameC
encoding:NSUTF8StringEncoding];
        NSLog(@"Character Name is: %s", nameC);
        NSLog(@"NSString Name is: %s", nameS);

        [pool drain];
        return 0;
}

Result:

<http://gnustep.8.n7.nabble.com/file/n36653/objc1.jpg>

Thanks a lot!



--
View this message in context: 
http://gnustep.8.n7.nabble.com/scanf-does-not-properly-pass-characters-tp36651p36653.html
Sent from the GNUstep - General mailing list archive at Nabble.com.

_______________________________________________
Discuss-gnustep mailing list
Discuss-gnustep@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnustep




reply via email to

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