 |
 |
How do I use C in Project Builder?
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2000
Status:
Offline
|
|
I just bought "A Book on C" and it explains how to program in C.
But when I try and run my little test programs, Nothing happens.
It supposed to give an output line with a Q. Then you reply to it by giving input, and it processed that and replies the outcome. Isn't there a sort of command line way to run C in Project Builder, (I want to use Project Builder because of the sintax checking.)
thx
Erick
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
You can write C programs in Project Builder by creating a "Standard Tool" project. Generally, when you run your program, the output appears in the Run pane in Project Builder (accessible via the tab marked "Run"). However, as it sounds like you've discovered, the Run window doesn't seem to work that well with command-line interactive programs. If you run your program, click in the Run pane, type something, and press return, you'll see your output all show up at once.
A better way to test it would be to open up Terminal and run your program from the command line. When you build your project (assuming you used the default settings for Project Builder), the program is stored in the "build" directory in your project folder. So if you created a project called "MyTest" and stored it in your Documents folder, you'd open Terminal and type:
cd Documents/MyTest/build
./MyTest
Then you can just keep the Terminal window open in the background and use it to test your program whenever you build it.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Status:
Offline
|
|
A better way if you're programming in C is just to open up the TextEditor supplied with OS X and type your program in there (don't forget to go to the "format" menu (I think) and make the file a text file instead of the default RTF). After you write your program, save it with the extension ".c" and then open up the terminal. cd to the directory where your file is saved. Type "cc <filename>" (that's compiling it)... then type "./a.out" (a.out is the name of the compiled version of your source code) to run it. So now when you want to edit the program because of bugs, etc., you just switch back to the text editor, amke changes, save, and then go to the terminal and do the cc and then the ./a.out to run it. What you can also do if you need to locate line numbers (given by the debugger in cc) is type "emacs <filename>" and edit the file in there and then when you're done, do control-x then control-c to exit. Emacs is basically a text editor within the terminal as far as Mac OS X goes.
But all of this is basic stuff if you take a CS 101 course at any college.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Sep 2000
Status:
Offline
|
|
I'm curious as to why you think TextEdit would make a better choice for editing C source than Project Builder, considering that Project Builder calls cc automatically, integrates the debugger, allows you to organize files, highlights syntax, does automatic indenting, does parenthase/bracket matching, etc. etc. What makes TextEdit a better choice?
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Status:
Offline
|
|
I should have definitely clarified my statements and fully read your previous post, Marshall, before asserting that "my way is best."
I was simply replying to his original question and simply scanned your post. Being a very inexperienced C.S. 101 student, I offered the method I used because I found it the simplest way to emulate on Mac OS X using emacs on a UNIX machine. Obviously ProjectBuilder is a better way to develop programs and after rereading your post, I've been able to discover more of the ins and outs of the application. Excuse my ignorance.
|
|
|
| |
|
|
|
 |
|
 |
|
tmarbois
|
|
Hi
Im also dabbling with C programming using Project Builder (Ive done command line 'old school' stuff - but I wanted to use project builder to get my hands dirty right away)
I wrote a simple program using stdio.h....
Do I now have to add stdio.h into the project as a header file (even though its referenced in my program.c file?)
It seems that my first program (which didnt use getchar or putchar) - worked fine without adding stdio.h as a header (I only used printf) -
When I went on to use putchar and getchar - the program failed to work as expected from within ProjectBuilder....(It works from the command-line)
Does anyone have insight on getting projectbuilder to act like the "old school" implementation?
Thanks!
Tj
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Oct 2000
Location: Caracas, Bolivarian Republic Of Venezuela
Status:
Offline
|
|
Originally posted by tmarbois:
Hi
Do I now have to add stdio.h into the project as a header file (even though its referenced in my program.c file?)
No, that's for your convenience only
[quote]
It seems that my first program (which didnt use getchar or putchar) - worked fine without adding stdio.h as a header (I only used printf) -
When I went on to use putchar and getchar - the program failed to work as expected from within ProjectBuilder....(It works from the command-line)
[\QUOTE]
The console window of ProjectBuilder (like the Xemacs one) does not support those functions. You shoud run the executable in the command line:
> cd src/myapp #the folder of your .pbprj file
> pbxbuild install # this will put the executable in your path
> rehash #let the shell see the new executable
> myapp
Does anyone have insight on getting projectbuilder to act like the "old school" implementation?
the old school way is:
> cd src/myapp
> cc myapp.c -o ~/bin/myapp
> rehash
> myapp
[This message has been edited by kvm_mkdb (edited 10-27-2000).]
|
Contra a barbárie, o estudo; Contra o individualismo, a solidariedade!
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|