Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 30, 2013, 11:19 PM   #1
smokeybear
macrumors newbie
 
Join Date: Jan 2013
First time C Programmer, need the basics!

Hey guys I'm wondering if any of you can help me out. I'm using a Macbook Pro to start my school career in computer science.

Basically I'm beginning my course in learning the basics of C, like some of variables, expressions, keywords, etc. But tomorrow is my first lab, and I'm wanting to get a head start.

I wondering where do I begin to write this language on my Macbook. I've already looked around and couldn't find anything specific, but I've read around that I can use terminal to write it...or compile it? I'm not positive as to where to begin to write or test stuff out.

Any words of wisdom would be greatly appreciated.
Thanks
smokeybear is offline   0 Reply With Quote
Old Jan 31, 2013, 01:44 AM   #2
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: San Diego, CA USA
The easiest way is to download XCode. One option is to use the IDE built-in to XCode to write C programs. The second is to download the "Command Line Utilities" (look in preferences) and use the Terminal to run gcc like any other Unix system.

There is a "Mac Programming" forum. You should take further programming questions there.
mfram is offline   0 Reply With Quote
Old Jan 31, 2013, 07:18 AM   #3
960design
macrumors 6502a
 
Join Date: Apr 2012
Location: Destin, FL
1) Download XCode from the App store ( for free ), as already mentioned
2) First App tutorial:
http://developer.apple.com/library/i...roduction.html
3) Feel all powerful!
__________________
TI-99/4A, tape cassette, 12" B&W Zenith
960design is offline   0 Reply With Quote
Old Jan 31, 2013, 02:16 PM   #4
N-M
macrumors newbie
 
Join Date: Jan 2013
http://c.learncodethehardway.org/
http://c.learncodethehardway.org/book/

BTW, you can also compile the source code in your browser (also good for sharing code snippets, etc.):
http://isocpp.org/blog/2013/01/online-c-compilers
// most of these are for C++ but will also compile the common subset; however, some (e.g, LiveWorkspace, Ideone) also give you an explicit choice to compile as C
N-M is offline   0 Reply With Quote
Old Jan 31, 2013, 06:01 PM   #5
smokeybear
Thread Starter
macrumors newbie
 
Join Date: Jan 2013
Thanks, didn't gather all the information I wanted, but I sure did learn a lot from the advice given and with the help of Google!

About to enter lab; going to continue to use this thread to ask questions if y'all wouldn't mind sticking around!
smokeybear is offline   0 Reply With Quote
Old Jan 31, 2013, 07:53 PM   #6
mbecker16
macrumors newbie
 
Join Date: Mar 2012
So I'm a recent college grad and I think I have a good idea of what your professors are going to be looking for. You likely won't be using an IDE (integrated development environment) for you first courses. They will want you to learn the basics before that.

When you write a C program, you need two things. First, a text editor that you will write your code with, and second, a compiler that will take your code and output a program. The compiler reads in the C code and compiles it, which means that it first does some magic, that you will likely learn later, to transform it into an executable binary file (a program). That executable will be specific to your Operating system and CPU architecture (x86 or x64 for intel macs).

There is much debate over which the best text editor to use but there are two categories, terminal text editors, such as vim or emacs, and gui editors, such as smultron.

As far as the compiler goes, most universities use the gnu compiler known as gcc (g++ for c++).

There are several ways to get gcc on your mac but the easiest is to just install xcode, which installs gcc for you. As a side note, Apple has been using the llvm compiler a lot recently instead of gcc. That doesn't mean that you want to use llvm cause it's better, it's just a note.

Once you have the tools, it's pretty easy.

You create a new text file and give some name and the .c extension (Ex: something.c). Save the file
and then compile it like so

gcc something.c

gcc will output the program with the name a.out

if you type a.out, it will execute your program.

You can look for an example of a hello world application in C if you want to try it out.

That's the basics and enjoy.
mbecker16 is offline   0 Reply With Quote
Old Feb 2, 2013, 01:33 AM   #7
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by mbecker16 View Post
There are several ways to get gcc on your mac but the easiest is to just install xcode, which installs gcc for you. As a side note, Apple has been using the llvm compiler a lot recently instead of gcc. That doesn't mean that you want to use llvm cause it's better, it's just a note.
It's not quite as simple as "just install Xcode". After installing Xcode, you have to open the preferences, go to the downloads tab, and download the command line tools.

Quote:
if you type a.out, it will execute your program.
I believe you have to actually type "./a.out", not just "a.out" for it to execute your code... if you'd like to execute it without the ./ (as you'd execute any other command line program) you'll need to put it in a special directory like /bin

Just because I brought the special directories up... I'd like to know, where should I put the executables for command line tools I write that I'd like to be able to easily access from any directory?
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Feb 2, 2013, 09:24 AM   #8
pitaya
macrumors member
 
Join Date: Jun 2012
Quote:
Just because I brought the special directories up... I'd like to know, where should I put the executables for command line tools I write that I'd like to be able to easily access from any directory?
/bin isn't magically special. It's in the shell's command search path.

/usr/local/bin is a good choice. Is it already listed in $PATH? I don't know if it exists on OS X out of the box. You could add a file to /etc/paths.d/, or an entry to /etc/paths, if you want to use it. If you'd like to run these tools out of your home directory, you could add, e.g., ~/bin to your $PATH. If you're using bash, try putting this in ~/.bash_profile:

Code:
export PATH="$PATH:$HOME/bin"
You might want to check out man hier (which also includes a link to some apple documentation).

Last edited by pitaya; Feb 2, 2013 at 09:30 AM.
pitaya 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

Similar Threads
thread Thread Starter Forum Replies Last Post
Time Machine basics. Specifically Sleeping Hard Drive? PicnicTutorials Mac Basics and Help 5 Feb 17, 2014 08:17 AM
Server basics mjsanders5uk Mac OS X Server, Xserve, and Networking 2 Aug 6, 2013 09:00 AM
rsync basics Kilamite Mac Applications and Mac App Store 1 Apr 21, 2013 10:17 AM
Learned the basics. What's next? omgitssum1 iPhone/iPad Programming 9 Jul 13, 2012 09:14 AM

Forum Jump

All times are GMT -5. The time now is 12:30 AM.

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

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC