Simple User Input in a CL Program

Discussion in 'Mac Programming' started by dieseltwitch, Dec 24, 2011.

  1. macrumors regular

    Joined:
    Jan 24, 2008
    #1
    I'm learning to program, but I'm having trouble trying to get data into my app. I've been watching the Lynda Videos and they are very helpful. However, there are many times when its stated in an early video "we will cover that later" or "you don't need to know that for now" but its never covered... very frustrating. its like learning how to drive a car but then never being shown how to actually get it started. lol

    What I'm looking for is some type of user input code. I want to write a simple app that takes in some data, say 3 or for numbers does some math on them and spits back out some result.
     
  2. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #2
    And what does CL refer to in this instance?
     
  3. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #3
    Command Line
     
  4. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #4
    Get yourself a reference book to use along with lynda.

    Is this Objective-C?

    C's scanf is the standard way of dealing with input.

    B
     
  5. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #5
    Any particular language?
     
  6. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #6
    Objective-C

    My end goal is to turn a lot of the calculations I do on a daily basis for work into apps or an app package.
    But i want to learn the language first.

    Ill try that scanf
     
  7. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #7
  8. dieseltwitch, Dec 24, 2011
    Last edited by a moderator: Dec 24, 2011

    thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #8
    Thanks that works, for now;

    Code:
     int myNumber;
            NSLog(@"Input:");
            scanf("%d", &myNumber);
            NSLog(@"Output: %d", myNumber);
    
    I did a little search on scanf.

    My next question is what does the & do in the scanf line?
     
  9. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #9
    It passes the location, known as an address, of the variable 'myNumber' so that 'scanf' can place the requested value in the variable 'myNumber'.
     
  10. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #10
    Make sense.

    Just checking, but the simple idea is the the & signifies the direction data is traveling in the program to the program its self?
     
  11. macrumors 6502a

    Joined:
    May 10, 2009
    Location:
    Des Moines, WA
    #11
    No, it simply passes the address of the variable instead of the contents of the variable.

    I'll amend that and say it does allow you to place thing into the variable from afar!
     
  12. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #12
    This discussion of pointers, passing by reference vs. passing by value, etc... is important for you to understand as it comes quite a bit with objects.

    Not learning this up front is likely to give you heartache later. JMHO.

    I think that Kochan is a better reference book, but Hillegass' new book http://www.bignerdranch.com/book/objective-c_programming_the_big_nerd_ranch_guide is a good source for the basic concepts.

    B
     
  13. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #13
    I agree! I'm just having a hard time knowing when to use * or & or nothing at all... lol I get the idea of the point just the when to use what is giving me to use trouble. but thats why I'm learning it in Command Line programs rather then deeper programs
     
  14. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #14
    That's why the two books I linked are Objective C, command line only. They have other books for Cocoa/Cocoa Touch. ;)

    Structurally, a book will give you more context and reinforce concepts appropriately.

    B
     
  15. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #15
    I saw those and will see if I get any barns & noble or amazon gift card tomorrow ;) I found that the apple reference is a great place.... so long as you know what you looking for. Same problem as trying to figure out how to spell a word by looking it up in the dic... lol
     
  16. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #16
    Out of those two books, what book would you recommend as a "read all book" rather then just a reference book?

    I found it both in the iTunes book store and have a gift card for that!
     
  17. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #17
    The Big Nerd Ranch Objective-C book will be the better one to get you started faster, once you finish it then go for the Kochan book which will be probably more useful in the long run.

    You can never use just one book as they all have different approaches. If you are new to programming (which it sound like you are) go for the Big Nerd Ranch book.

    That being said once you finish the book I wouldn't suggest jumping to the next Big Nerd Ranch book as they are not written for beginners (the Obj-C book is the only exception).

    I guess what I'm saying is do this order:

    1. Big Nerd Ranch Objective-C book
    2. Steve Kochan Objective-C book
    3. Big Nerd Ranch Mac OS Programming or iOS book (whichever you are going for).
     
  18. thread starter macrumors regular

    Joined:
    Jan 24, 2008
    #18
    Thanks!
     
  19. macrumors 604

    chrono1081

    Joined:
    Jan 26, 2008
    Location:
    Isla Nublar
    #19
    No problem. Just remember when programming that sometimes you have to skip over something confusing at first to understand it later.

    If you run in to a lot of problems going through the first book, grab the second book and use it to supplement what you are learning in the first.
     

Share This Page