Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ETID

macrumors regular
Original poster
Jan 6, 2008
148
0
Hello I've started a programming in C course for my engineering degree. At the moment I'm using Visual C++/C to do this but I was just wondering if there is a similar variant for mac as I prefer to work in OSX than XP.

Thanks for any help.
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
Hello I've started a programming in C course for my engineering degree. At the moment I'm using Visual C++/C to do this but I was just wondering if there is a similar variant for mac as I prefer to work in OSX than XP.

Thanks for any help.

Every Macintosh comes with XCode, which comes with compilers for C, C++, Objective-C, Java, plus perl, python, ruby, and a few other languages.
 

TygerMac

macrumors newbie
Mar 10, 2008
28
0
New Hampshire
Yes, it is on the install disc. Or you can download it from the Developers site at Apple. I just started C myself and xcode is great. If you find any good sites with tutorials or a good book, please let me know!
 

ETID

macrumors regular
Original poster
Jan 6, 2008
148
0
It looks gr8 but unfortunately I haven't been able to get even a simple hello world in C to work. I just get like 120 errors, have no idea what is going on.

If anyone does know of a tutorial site or similar that would be awesome
 

Cromulent

macrumors 604
Oct 2, 2006
6,812
1,100
The Land of Hope and Glory
It looks gr8 but unfortunately I haven't been able to get even a simple hello world in C to work. I just get like 120 errors, have no idea what is going on.

If anyone does know of a tutorial site or similar that would be awesome

Give us some details and we might be able to solve the problem.

No details = no help in this forum I'm afraid.
 

ETID

macrumors regular
Original poster
Jan 6, 2008
148
0
right so I just want write a simple C code to begin with. I thought this was how I would go about doing it. Xcode>new project>blank project>new file>c file.

I then input this code in
/*hello world*/
include <stdio.h>
main()
{
printf ("hello world\n");
}

If that helps what I'm on about.

I'm used to using visual c++/C for this so I didn't really know what to do for some things. For instance where I regularly use (hash symbol)include etc. What do I do as macs don't seem to have a hash key
 

Cromulent

macrumors 604
Oct 2, 2006
6,812
1,100
The Land of Hope and Glory
right so I just want write a simple C code to begin with. I thought this was how I would go about doing it. Xcode>new project>blank project>new file>c file.

I then input this code in
/*hello world*/
include <stdio.h>
main()
{
printf ("hello world\n");
}

If that helps what I'm on about.

I'm used to using visual c++/C for this so I didn't really know what to do for some things. For instance where I regularly use (hash symbol)include etc. What do I do as macs don't seem to have a hash key

You main function should be int main (int argc, const char * argv[]).

Do not make a blank project.

Xcode > New Project > Command Line Utility > Standard Tool.
 

ETID

macrumors regular
Original poster
Jan 6, 2008
148
0
thanks got it working. Thanks to all you very nice people
 

toddburch

macrumors 6502a
Dec 4, 2006
748
0
Katy, Texas
I use Xcode every day for C/C++ programs and it's great. You can, however, also use the command line in Terminal. It's pretty simple.

Code:
cat > myprog.c
#include <stdio.h>
int main(void) { 
printf("Hello World!\n") ; 
return 0 ; 
} 
CTRL+D 

gcc myprog.c -o myprog 
./myprog

is all it takes. ;)
 

ETID

macrumors regular
Original poster
Jan 6, 2008
148
0
I use Xcode every day for C/C++ programs and it's great. You can, however, also use the command line in Terminal. It's pretty simple.

Code:
cat > myprog.c
#include <stdio.h>
int main(void) { 
printf("Hello World!\n") ; 
return 0 ; 
} 
CTRL+D 

gcc myprog.c -o myprog 
./myprog

is all it takes. ;)

When doing this in terminal how would you get the hash for the #include <stdio.h> because I don't have one on my keyboard and even if I use a windows keyboard the hash key just turns into a backslash.
 

Pring

macrumors 6502
Sep 17, 2003
310
0
When doing this in terminal how would you get the hash for the #include <stdio.h> because I don't have one on my keyboard and even if I use a windows keyboard the hash key just turns into a backslash.


In UK Keyboard setup it's alt-3 to get a #.
 

ETID

macrumors regular
Original poster
Jan 6, 2008
148
0
Thanks for the alt-3 its a life saver! Since i started this thread I've already made so much progress.

cheers
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.