PDA

View Full Version : Simple User Input in a CL Program




dieseltwitch
Dec 24, 2011, 05:04 PM
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.



lloyddean
Dec 24, 2011, 05:07 PM
And what does CL refer to in this instance?

dieseltwitch
Dec 24, 2011, 05:08 PM
And what does CL refer to in this instance?

Command Line

balamw
Dec 24, 2011, 05:10 PM
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

lloyddean
Dec 24, 2011, 05:10 PM
Any particular language?

dieseltwitch
Dec 24, 2011, 05:22 PM
Any particular language?

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

balamw
Dec 24, 2011, 05:28 PM
By the time you make an app out of it you will replace scanf with appropriate Cocoa/Cocoa Touch UI elements. This is one reason they don't focus on this.

Again, pick up a book as reference material like Kochan http://www.informit.com/store/product.aspx?isbn=9780132900911 for $20 if you act fast http://www.informit.com/promotions/promotion.aspx?promo=138703.

B

dieseltwitch
Dec 24, 2011, 05:28 PM
Thanks that works, for now;

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?

lloyddean
Dec 24, 2011, 05:35 PM
It passes the location, known as an address, of the variable 'myNumber' so that 'scanf' can place the requested value in the variable 'myNumber'.

dieseltwitch
Dec 24, 2011, 05:41 PM
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?

lloyddean
Dec 24, 2011, 05:51 PM
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!

balamw
Dec 24, 2011, 06:33 PM
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

dieseltwitch
Dec 24, 2011, 06:36 PM
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.

B

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

balamw
Dec 24, 2011, 06:40 PM
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

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

dieseltwitch
Dec 24, 2011, 06:43 PM
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

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

dieseltwitch
Dec 24, 2011, 08:39 PM
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

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!

chrono1081
Dec 24, 2011, 09:09 PM
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!

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).

dieseltwitch
Dec 24, 2011, 09:14 PM
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).

Thanks!

chrono1081
Dec 25, 2011, 05:44 AM
Thanks!

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.