Re: Newbie C Questions
Re: Newbie C Questions
- Subject: Re: Newbie C Questions
- From: Ondra Cada <email@hidden>
- Date: Wed, 30 Jan 2002 14:44:58 +0100
Tom,
>
>>>>> Tom McKenna (TMK) wrote at Tue, 29 Jan 2002 22:05:22 -0500:
TMK> * When I am using Project Builder and I want to create a simple C
TMK> application, what kind of project should I be opening? (I have been
TMK> using the 'Standard Tool' option in PB...)
That's right.
TMK> * Once I finish this book on C, I would like to learn Objective-C. Is
TMK> there a beginner's book that doesn't work under the assumption that
youTMK> know C++ or Java? If not, what should I do next?
Forget books. Just learn plain C (go easy on arrays, skip completely
bitfields and unions, skip completely all standard functions but plain
printf: you won't need that, at least not soon).
As soon you are reasonably at home with C, just study
/Developer/Documentation/Cocoa/ObjectiveC/ObjC.pdf. The book is pretty good,
does not presume any C++ or Java nonsense, and is reasonably short (which is
just a side-effect of ObjC being surprisingly simple).
Incidentally, that you don't know C++ is a big advantage. The thing would
mislead you *HUGELY* -- a real object-oriented system, like we have in ObjC,
differs from what C++ offers very considerably. If you want more information
and related books, go shopping for _Smalltalk_ titles, not C++.
Then start learning Foundation and AppKit, preferrably by small steps and
via examples: the frameworks are actually very intuitive and documentation
(but for some new things) is good, but the scope of the whole thing is
_VAST_, and therefore there is toooooo many things to learn at this level.
Do, though, spend a day or so by scanning the
.../Cocoa/Reference/Foundation/ObjC_classic/Foundation.pdf, and the similar
AppKit book. Don't want to read all, just scan there to get an overall image
which is supported by which classes.
TMK> * One of my tutorial apps compiles fine in PB, but it won't run in PB.
TMK> It does run perfectly in the Terminal. Am I doing something wrong?
Yep, presuming the PB console window supports properly the standard input ;)
Actually I don't know, there might be a trick how to do that, but I know none.
In practice it is not a real problem, since you would generally write
GUI-based things, which use different input. For testing purposes I recommend
you to stick with commandline arguments -- like this:
/* Filename: Avg.C */
/* Computes the average of three class grades */
// changed to take data from commandline
main (int argc,char *argv[])
{
float gr1, gr2, gr3;
float avg;
if (argc<4) {
printf("Usage: %s <first student's grade> <2nd one> <3rd one>\n",argv[0]);
return 0;
}
gr1=atof(argv[1]);
gr2=atof(argv[2]);
gr3=atof(argv[3]);
// Calculates the average of the three student's grades
avg = (gr1 + gr2 + gr3) / 3.0;
printf("The student average is %.2f\n", avg);
// *** better to finish lines by \n than to begin with it (normally, as
soon as \n is written out, the line occurs in Terminal -- not before)
return 0;
}
Incidentally, don't learn those argc/argv in unneeded details -- with
Foundation Kit in near future you'll see better ways to access command line
arguments. This is just meantime...
TMK> Thanks for any and all help, advice you can offer!
You are welcome in the wonderful world of OO and Cocoa!
---
Ondra Cada
OCSoftware: email@hidden
http://www.ocs.cz
2K Development: email@hidden
http://www.2kdevelopment.cz
private email@hidden
http://www.ocs.cz/oc