PDA

View Full Version : A noob needing help with C




ETID
Mar 17, 2008, 01:02 PM
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
Mar 17, 2008, 01:18 PM
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.

ETID
Mar 17, 2008, 01:20 PM
Awesome. Is this located on the install disc?

TygerMac
Mar 17, 2008, 01:31 PM
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
Mar 17, 2008, 02:06 PM
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
Mar 17, 2008, 02:09 PM
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
Mar 17, 2008, 02:16 PM
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
Mar 17, 2008, 02:32 PM
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.

Vader
Mar 17, 2008, 02:38 PM
you are including a header file, does that header file exist?

Cromulent
Mar 17, 2008, 02:41 PM
you are including a header file, does that header file exist?

Ah good eyes :).

Yes look again at your include statement as well.

ETID
Mar 17, 2008, 02:53 PM
thanks got it working. Thanks to all you very nice people

toddburch
Mar 17, 2008, 02:57 PM
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.


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
Mar 17, 2008, 04:20 PM
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.


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
Mar 17, 2008, 04:39 PM
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
Mar 18, 2008, 04:53 AM
Thanks for the alt-3 its a life saver! Since i started this thread I've already made so much progress.

cheers