Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Sep 16, 2009, 05:47 AM   #1
aningbo
macrumors newbie
 
Join Date: Sep 2009
MAC newbie: how to write "hello world" in C

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.

Code:
#include <stdio.h>
main()
{
printf('hello');
}
aningbo is offline   0 Reply With Quote
Old Sep 16, 2009, 05:58 AM   #2
macuser154
macrumors 6502
 
Join Date: Jan 2009
Location: UK
Quote:
Originally Posted by aningbo View Post
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.

Code:
#include <stdio.h>
main()
{
printf('hello');
}
Install Xcode, it is on your Leopard disc. I think you can get it online as well.
__________________
'07 MacBook Pro 15" 2.4GHz - '09 Mac Mini 2.53GHz - '09 iPhone 3GS 32GB - '10 iPad WIFI + 3G 64GB
macuser154 is offline   0 Reply With Quote
Old Sep 16, 2009, 06:06 AM   #3
Dale Cooper
macrumors regular
 
Join Date: Sep 2005
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.
__________________
Bob

Last edited by Dale Cooper; Sep 16, 2009 at 06:12 AM.
Dale Cooper is offline   0 Reply With Quote
Old Sep 16, 2009, 09:08 AM   #4
mslide
macrumors 6502a
 
Join Date: Sep 2007
Quote:
Originally Posted by aningbo View Post
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).
mslide is offline   0 Reply With Quote
Old Sep 16, 2009, 10:21 AM   #5
aningbo
Thread Starter
macrumors newbie
 
Join Date: Sep 2009
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.
aningbo is offline   0 Reply With Quote
Old Sep 16, 2009, 10:34 AM   #6
GorillaPaws
macrumors 6502a
 
GorillaPaws's Avatar
 
Join Date: Oct 2003
Location: Richmond, VA
Quote:
Originally Posted by aningbo View Post
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.
GorillaPaws is offline   0 Reply With Quote
Old Sep 16, 2009, 01:34 PM   #7
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: Seattle, WA
Also, your code won't work:
Your code:
Code:
#include <stdio.h>
main()
{
  printf('hello');
}
Working code:
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
lee1210 is offline   0 Reply With Quote
Old Sep 16, 2009, 03:41 PM   #8
zippyfly
macrumors regular
 
Join Date: Mar 2008
Good stuff here also:

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

http://developer.apple.com/mac/libra.../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).

Last edited by WildCowboy; Sep 16, 2009 at 03:46 PM. Reason: post merge
zippyfly is offline   0 Reply With Quote
Old Sep 16, 2009, 08:21 PM   #9
electroshock
macrumors 6502a
 
electroshock's Avatar
 
Join Date: Sep 2009
Quote:
Originally Posted by aningbo View Post
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).
electroshock is offline   0 Reply With Quote
Old Sep 16, 2009, 08:26 PM   #10
Chundles
macrumors G4
 
Chundles's Avatar
 
Join Date: Jul 2005
Location: The Gong, Australia
Quote:
Originally Posted by lee1210 View Post

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.
__________________
This is going straight to the Pool Room
Chundles is offline   0 Reply With Quote
Old Sep 16, 2009, 10:05 PM   #11
zippyfly
macrumors regular
 
Join Date: Mar 2008
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?
zippyfly is offline   0 Reply With Quote
Old Sep 16, 2009, 11:10 PM   #12
notjustjay
macrumors 603
 
notjustjay's Avatar
 
Join Date: Sep 2003
Location: Canada, eh?
100 MEG cap?

Man, a good YouTube video or two would suck that back without any difficulty.
__________________
.
notjustjay is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Tutorial: How to get PCSX2 to run on Mac (without BootCamp) Mirrors Mac Applications and Mac App Store 22 Jun 14, 2013 08:19 PM
How to convinc my parents to let me buy a 17" MacBook pro Ulf1103 Buying Tips and Advice 55 Feb 20, 2012 08:11 AM
How to supercharge Mini? ranny2 Mac mini 18 Oct 27, 2011 08:53 PM
Does anybody know how to get TweetTask? xmelissaxmayhem Jailbreaks and iOS Hacks 3 Jul 3, 2011 01:21 AM
[HOW TO] DIY iPhone 4 Swivel Car Mount QuarterSwede iPhone Accessories 13 Mar 8, 2011 02:51 PM


All times are GMT -5. The time now is 06:09 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC