stringByAppendingFormat confusion (casting?)

Discussion in 'Mac Programming' started by zippyfly, Sep 15, 2009.

  1. zippyfly macrumors regular

    Joined:
    Mar 22, 2008
    #1
    How come I get an error about "makes pointer from integer without a cast" from this code:

    Code:
    #import <Foundation/Foundation.h>
    
    int main (int argc, const char * argv[]) {
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    	
    	NSString *myString = @"Results: ";
    	
    	NSLog(@"%@",myString);
    
    	myString = [myString stringByAppendingString:@"The winner is number "];
    	
    	NSLog(@"%@",myString);
    	
    	int i = 1;
    
    [B]	myString = [myString stringByAppendingFormat:("%i",i)];[/B]
    
    	NSLog(@"%@",myString);
    	
        [pool drain];
        return 0;
    	
    }
    
    I tried writing

    Code:
    myString = [myString stringByAppendingFormat:("%i", [B](int)[/B] i)];
    
    but it didn't work either.
     
  2. wlh99 macrumors 6502

    Joined:
    Feb 7, 2008
    #2
    Code:
    myString = [myString stringByAppendingFormat:([B]@[/B]"%i",i)];
    
     
  3. zippyfly thread starter macrumors regular

    Joined:
    Mar 22, 2008
    #3
    I tried that before and it said (and still says):

    Format not a string literal and no format arguments.
     
  4. Arrg macrumors newbie

    Joined:
    Jan 22, 2008
    #4
    Drop the parenthesis

    Code:
    myString = [myString stringByAppendingFormat:@"%i", i];
     
  5. zippyfly thread starter macrumors regular

    Joined:
    Mar 22, 2008
    #5
    Much thanks. Works now:

    Code:
    myString = [myString stringByAppendingFormat:@"%i",i];
     

Share This Page