Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > How do I use C in Project Builder?

How do I use C in Project Builder?
Thread Tools
Fresh-Faced Recruit
Join Date: Oct 2000
Status: Offline
Reply With Quote
Oct 14, 2000, 05:24 AM
 
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
Reply With Quote
Oct 14, 2000, 12:52 PM
 
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
Reply With Quote
Oct 14, 2000, 07:01 PM
 
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
Reply With Quote
Oct 14, 2000, 07:41 PM
 
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
Reply With Quote
Oct 15, 2000, 08:09 PM
 
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
Guest
Status:
Reply With Quote
Oct 23, 2000, 12:56 AM
 
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
Reply With Quote
Oct 27, 2000, 01:00 PM
 
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!
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:45 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2