Need help!!! (scanf)

Discussion in 'Mac Programming' started by Boeing747, Jul 25, 2011.

  1. Boeing747, Jul 25, 2011
    Last edited by a moderator: Jul 25, 2011

    Boeing747 macrumors member

    Joined:
    Jul 10, 2011
    Location:
    In Steve Job's Closet
    #1
    Hello everyone,

    I'm trying to make a mac application that asks you what your name & age is then tells you the lowest aged person you can date.

    Here's my code:
    Code:
    int main (int argc, const char * argv[]){
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
        
        int dateAge;
        NSString *name;
        
        
        NSLog(@"What is your name?");
        scanf("%@", &name);
        NSLog(@"How old are you?");
        scanf("%i", &dateAge);
        
        NSLog(@"Ok, %@ you can date people that are %i years old or older.",name,dateAge/2+7);
        
        
    
        [pool drain];
        return 0;
         }
    
    Is there something I should be using instead of scanf for NSStrings?

    Thank you.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I think you'll have to scan into a char buffer then convert to NSString.
     
  3. Boeing747 thread starter macrumors member

    Joined:
    Jul 10, 2011
    Location:
    In Steve Job's Closet
    #3
    How do I do that?

    I'm a noob at programming.
     
  4. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    What have you tried? What documentation have you read to try and answer your question? What are you using to learn plain, basic C (since that's where scanf and char buffers come from)?

    If you are just expecting code provided then you're probably in the wrong place.
     
  5. Boeing747 thread starter macrumors member

    Joined:
    Jul 10, 2011
    Location:
    In Steve Job's Closet
    #5
    thenewboston on youtube

    I'm trying to expand and do other things other than just trying to do what he does. I'm on lesson 26.
     

Share This Page