1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Simple User Input in a CL Program

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

  1. macrumors regular

    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

    And what does CL refer to in this instance?
  3. macrumors regular

    Command Line
  4. Moderator


    Staff Member

    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.

  5. macrumors 6502a

    Any particular language?
  6. macrumors regular


    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


    Staff Member

  8. dieseltwitch, Dec 24, 2011
    Last edited by a moderator: Dec 24, 2011

    macrumors regular

    Thanks that works, for now;

     int myNumber;
            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

    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. macrumors regular

    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

    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


    Staff Member

    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.

  13. macrumors regular

    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


    Staff Member

    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.

  15. macrumors regular

    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. macrumors regular

    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


    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. macrumors regular

  19. macrumors 604


    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