| Article: |
C is for Cocoa | |
| Subject: | This made me install the dev tools | |
| Date: | 2003-07-23 20:10:14 | |
| From: | anonymous2 | |
|
Thanks. Excellent article. Looking forward to lesson 2.
|
||
Showing messages 1 through 5 of 5.
-
Re: This made me install the dev tools
2003-07-23 21:04:40 anonymous2 [View]
-
Re: This made me install the dev tools
2003-07-23 21:07:56 anonymous2 [View]
Whoops! I should have tested the program before I hit 'Submit'. Here is the revised code:
#include <stdio.h>
int main()
{
//Computes our favorite number
int favoriteNumber = (3 * 4) / 2; /*is anyone's favorite number not an int? */
favoriteNumber = favoriteNumber + 2;
/* now let's tell the world
what our favorite number is! */
printf("My favorite number is %d!\n", favoriteNumber);
}
-
Re: This made me install the dev tools
2003-07-26 02:00:07 anonymous2 [View]
misssing
return (0);
are we? :) -
Re: This made me install the dev tools
2003-09-03 19:48:45 anonymous2 [View]
Not really. return 0; is optional in standard, modern C++ - and by extension, I'd assume the most recent C spec.
Though gcc accepts some C++ syntaxes in C-compiling mode. -
Re: This made me install the dev tools
2003-07-23 22:17:35 anonymous2 [View]
Presuming somebody interested in this tutorial is going to be working on a Mac, why would they bust out vi or emacs or pico?
You can do all your typing in Project Builder. It's a perfectly servicable text editor. Or use BBEdit / BBEdit Lite. Much friendlier.



Getting a C program to run involves three steps:
1. Create your C source file. If you've never used vi or emacs then I would recommend pico. Save the source file as 'lesson1.c'.
2. Compile it into machine code:
gcc lesson1.c
3. Run your program and see your happy result:
./a.out
I'm not going to go into how or why any of this works; I will let the excellent tutorial run its course. I will, however, say that despite what you've read, the line that begins with '#' (it's not a comment) must remain as an independent line.
Here is the entire program:
#include <stdio.h>
void main()
{
//Computes our favorite number
int favoriteNumber = (3 * 4) / 2; /*is anyone's favorite number not an int? */
favoriteNumber = favoriteNumber + 2;
/* now let's tell the world
what our favorite number is! */
printf("My favorite number is %d!", favoriteNumber);
}