Can't you C ?

ApeintheShell

Registered
A just found a good C primer book in our basement.
I've read the intro and it says i need a editor and compiler.
I tried doing some coding in text edit but it doesn't save right.
Apparently i can compile in unix, not so sure. But i need a text editor.

1) Will pico be able to save my files with the .c extension?

2) or should i install the developer tools that came with 10.2?
 
You can use any editor to create .c files that will write out files in plain text format (be sure to tell TextEdit to use plain text rather that RTF).

pico will work just fine if you want to work with a Terminal editor.

hth,
bear
 
alright i used pico to create a file called monkey.c
it asks how many monkeys you have..haha
i used cc monkey.c to compile it and i end up with a.out in the home directory.
how do i get the monkey questionaire to run?
 
You should just be able to type 'a.out'. Under any unix shell, you simply reference an executable file to cause it to run. This is true of shell scripts as well as compiled programs.

Caveat is: the file must have executable permission. The cc compiler should have marked the file as such, but if not

chmod a+x a.out

should do the trick.

hth,
bear
 
(As paracord points out, you need to enter ./a.out because the executable probably isn't in the shell's search path. This presumes the "current directory" is the location of a.out. If not then cd folder/containing/a.out)
 
Compiling files as a.out all the time gets annoying. Try using the following,

monkey.c -o newname

Where "newname" is the title you want for the compiled file. You could also try typing "man gcc" in the terminal to get more info on this.

Also, to prevent having to issue the full path (or to have to use ./) everytime you want to execute you're new app, try the following. Add a "bin" folder to you're home directory and then include the path to it in you're .tcshrc file (i.e /Users/yourname/bin [where "yourname" is you're user name]). Do a search on how to create the .tcshrc file - there is plenty of info around, but if you want some help give me a shout

Below is part of my .tcshrc file so that you can see what I mean (note this should be all on one line).

setenv PATH /Users/will/bin:/usr/X11R6/bin:/opt/local/bin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Will:)
 
Back
Top