views:

1556

answers:

3

i want to casting my NSString to a constant char the code is shown below :

NSString *date = @"12/9/2009";
char datechar = [date UTF8String]

NSLog(@"%@",datechar);

however it return the warning assignment makes integer from pointer without a cast and cannot print the char properly,can somebody tell me what is the problem

+1  A: 

I would add a * between char and datechar (and a %s instead of a %@):

NSString *date=@"12/9/2009"; char * datechar=[date UTF8String];
NSLog(@"%s",datechar);
mouviciel
+5  A: 

Try something more like this:

NSString* date = @"12/9/2009";
char* datechar = [date UTF8String];
NSLog(@"%s", datechar);

You need to use char* instead of char, and you have to print C strings using %s not %@ (%@ is for objective-c id types only).

Joel Levin
+2  A: 

I think you want to use:

const char *datechar = [date UTF8String];

(note the * in there)

Marc Novakowski