PDA

View Full Version : MAC newbie: how to write "hello world" in C




aningbo
Sep 16, 2009, 05:47 AM
i just bought macbook pro and can't figure out how to start off. i found the terminal but there's not a single editor preinstalled! i'm using mac os x 10.5.7

could anyone give me a brief introduction on how to write a simple C code, compile it instruction. i can't find it anywhere! thanx.

#include <stdio.h>
main()
{
printf('hello');
}



macuser154
Sep 16, 2009, 05:58 AM
i just bought macbook pro and can't figure out how to start off. i found the terminal but there's not a single editor preinstalled! i'm using mac os x 10.5.7

could anyone give me a brief introduction on how to write a simple C code, compile it instruction. i can't find it anywhere! thanx.

#include <stdio.h>
main()
{
printf('hello');
}

Install Xcode, it is on your Leopard disc. I think you can get it online as well.

Dale Cooper
Sep 16, 2009, 06:06 AM
You can use TextEdit, or just type vim in the Terminal.

Compile using terminal commands:
gcc filename.c -o name of compiled app

Run the program using
./name of compiled app

I would recommend installing the Developer Tools from your Leopard DVD, but using XCode for small "Hello World"-ish apps is a lot of extra work compared to just using a plain text editor and the terminal for compiling and running.

For a text editor, I would recommend MacVim if you plan on doing a lot of programming (has a steep learning curve, but is very efficient once you've learned all the commands), or perhaps TextWrangler. Both are free.

mslide
Sep 16, 2009, 09:08 AM
i found the terminal but there's not a single editor preinstalled!

TexTEdit, vim, emacs and pico/nano come preinstalled and I wouldn't be surprised if there are other lesser known ones preinstalled.

If you want to program on a Mac, download XCode (or install it from your OSX DVD). It will include not only the XCode IDE but the typical GNU development tools (gcc/g++, gdb, make, etc).

aningbo
Sep 16, 2009, 10:21 AM
thanx guys.

really appreciate your time. i got it working with xcode available in the dvd. i was wondering as to how i would download such a huge file since m in college with proxy and 100MB limit

thanx agaiun.

GorillaPaws
Sep 16, 2009, 10:34 AM
i was wondering as to how i would download such a huge file since m in college with proxy and 100MB limit

Downloading caps are such an alien concept to me. To download updates and such you might be able to talk to your college's computer science department, or the IT department who manages your account to see if they would be willing to download the update for you and save it to a thumb-drive or other media.

lee1210
Sep 16, 2009, 01:34 PM
Also, your code won't work:
Your code:

#include <stdio.h>
main()
{
printf('hello');
}


Working code:

#include <stdio.h>
int main(int argc, char *argv[]) {
printf("Hello\n");
return 0;
}


Single quotes are for character literals. Passing a character literal to something expecting a char * will not turn out well for you.

As for you downloading large files... maybe you can go to a lab, download the large file to a keychain drive, etc. and go about it that way? 100MB (per day? week? month?) seems like a pretty severe restriction.

-Lee

zippyfly
Sep 16, 2009, 03:41 PM
Good stuff here also:

http://developer.apple.com/mac/library/navigation/

http://developer.apple.com/mac/library/documentation/DeveloperTools/Conceptual/A_Tour_of_Xcode/000-Introduction/qt_intro.html

(Note that you are using a previous version of OS X and Xcode ... versus what you will find on the Apple site, which is on the Snow Leopard distribution; as to what is different, it depends which aspect you are looking at, although most major concepts are the same; Xcode UI differs somewhat).

electroshock
Sep 16, 2009, 08:21 PM
thanx guys.

really appreciate your time. i got it working with xcode available in the dvd. i was wondering as to how i would download such a huge file since m in college with proxy and 100MB limit

You'll occasionally need to install large patches or major Xcode updates (100-300 MB). When you do, you may want to bum a ride, walk, or catch a bus to the town's public library if they have wireless internet and download large stuff that way then go back to school. Or a nearby Starbucks or some other establishment with uncapped wireless service and buy some drinks/food.

Also, you may want to consider getting a great book that shows screenshots and step by step for setting up Xcode projects, doing small projects and building up C and Objective-C knowledge. I like to recommend Aaron Hillegass's Cocoa Programming for MacOS X (3rd edition).

Chundles
Sep 16, 2009, 08:26 PM
As for you downloading large files... maybe you can go to a lab, download the large file to a keychain drive, etc. and go about it that way? 100MB (per day? week? month?) seems like a pretty severe restriction.

-Lee

Our university had a 100MB per semester (half-year) limit before we had to use an outside provider.

It sucked.

We see all those folks in the states agonising over a 250GB monthly download cap and wish we could get anywhere near that. Biggest I've seen here is 150GB but that was mostly confined to off-peak.

zippyfly
Sep 16, 2009, 10:05 PM
I'm curious; do the universities then expect the students to find alternative broadband methods? Is it even possible to deploy residential broadband in the dorm room, or are students expected to fork out even more money for expensive 2G/3G connectivity?

notjustjay
Sep 16, 2009, 11:10 PM
100 MEG cap?

Man, a good YouTube video or two would suck that back without any difficulty.