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

Preston019

macrumors newbie
Original poster
Dec 26, 2012
2
0
Hey guys,

I'm taking a class that requires us to program using C.
I've downloaded and set up Xcode 4, but when I run the program, I only get the output, down in the lower left screen, from one of the files I have and I have two and they both work.
Also, is there a way, in Xcode, to run just one file in a project at a time? I don't want to have a ton of projects just for one file.

On another note, Xcode seems very advanced and overwhelming for me right now, is there a program that I can type my code and then run it in a shell, kind of like IDLE for Python? If not, I'd still like to be able to use Xcode.

I know I can use terminal, but I'm trying to use that as a last resort.

Thank You
 

djholman

macrumors newbie
Jul 15, 2013
15
3
If you want to program in C your FIRST resort should be the terminal and a program called vi.
 

eoblaed

macrumors 68030
Apr 21, 2010
2,972
3,033
Like the others I use terminal, vim, and make/gcc. That's a whole other kit of things to learn if you don't know them already, but I imagine Xcode also has a steep learning curve.

That's the thing about learning your first programming language: you have to learn more than just the language, you also need to learn how to use at least one development environment.
 

unterrible

macrumors newbie
Aug 26, 2013
1
0
You can run just one C file in Xcode by unchecking the "Target Membership" checkbox of the files you don't want to run. "Target Membership" is located in the File Inspector window, which is on the right-side by default. If you closed the File Inspector window, you can access it through the View>Utilities>Show File Inspector menu.
 

Watabou

macrumors 68040
Feb 10, 2008
3,425
755
United States
If you want to program in C your FIRST resort should be the terminal and a program called vi.

Vim not vi (and yes, there is a difference, the main difference being that vim is more powerful and better). Barely any modern OS out there has vi installed.

If you find a 'vi' program, it's simply a symlink to vim. Sorry it's just a pet peeve of mine.

And I agree with the above, if you just go in using an IDE, you won't learn anything. For C, C++, you most likely never need an IDE. Go with vim or any other text editor. I recommend vim because it will also expose you to the terminal and gcc/clang.

If you absolutely don't want a terminal text editor, try other free text editors out there like Textmate 2, Sublime Text (free to try indefinately), or TextWrangler.
 
Last edited:

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,544
6,042
T.T

Don't use a terminal editor. Everyone suggesting that, knock it off. Those in the party of nay sayers against beginners using IDEs are right: they're too complicated. About the only worst suggestion for a beginner programmer is to use an IDE is to tell them to use a terminal editor. If they pursue that route, they're forced to learn more than an IDE + language: they're forced to learn an entirely new kernel (because chances are they've never used one without a GUI), the editor, and the language.

My suggestion: just use Sublime. It's simple and intuitive enough. Unless I'm mistaken, I believe the default download comes with a compile button in it that automatically detects your language and will compile / run your code.

It has considerable less magic than an IDE, but just a bit more than a terminal program, and it's a lot easier to learn/use.
 

ravenvii

macrumors 604
Mar 17, 2004
7,585
492
Melenkurion Skyweir
To the above, when I said I use Vim, I actually meant MacVim. I know, I know, a sinful omission, I apologize. :p

Though the recommendation for Sublime Text is a very good one -- I really like it as well.
 

robvas

macrumors 68040
Mar 29, 2009
3,240
629
USA
vi/vim is a huge PITA for users, especially a new user. I love it but nobody else can figure out why. Using Sublime or Komodo or Textwrangler is a much better bet

That said, if you're going to compile from the terminal it's only going to help you to learn to edit from the terminal. As well as use grep and awk and sed and...
 
Last edited:

ravenvii

macrumors 604
Mar 17, 2004
7,585
492
Melenkurion Skyweir
vi/vim is a huge PITA for users, especially a new user. I love it but nobody else can figure out why. Using Sublime or Komodo or Textedit is a much better bet

That said, if you're going to compile from the terminal it's only going to help you to learn to edit from the terminal. As well as use grep and awk and sed and...

You forgot a /s there.
 

firewood

macrumors G3
Jul 29, 2003
8,107
1,343
Silicon Valley
You can use Xcode to install the command-line tools, and also to create and edit your pure C programs.

Then, with the command-line tools installed by Xcode, you can use cc or gcc (really just symlinks to cfront/llvm under the current OS X) to compile and then run your programs from a Terminal shell (or even from an ssh remote login to your Mac from your iPhone or iPad !).

I prefer using vi (really a symlink to vim) for quick edits, but the Xcode editors for writing large multi-file-many-thousand line C programs.

If needed, you can switch back to creating an Xcode target for your C program if you wish to use the visual context-aware debug mode of lldb.
 

Preston019

macrumors newbie
Original poster
Dec 26, 2012
2
0
Hey guys,

Thanks for all of the suggestions!

I've been kind of fiddling around with Xcode and I like how it tells you if something is wrong before even compiling and running it. I think I might just write my text in Xcode and just compile and run with Terminal.

I need to learn eventually, right? :rolleyes:
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
9,544
6,042
Hey guys,

Thanks for all of the suggestions!

I've been kind of fiddling around with Xcode and I like how it tells you if something is wrong before even compiling and running it. I think I might just write my text in Xcode and just compile and run with Terminal.

I need to learn eventually, right? :rolleyes:

Whatever floats your boat. The language doesn't change as a result of your using Xcode instead of something else. There's just the issue that novice programmers tend to fail to see where one thing ends and another begins in an IDE since everything is integrated (what the I stands for) together.
 

Winni

macrumors 68040
Oct 15, 2008
3,207
1,196
Germany.
Hey guys,

Thanks for all of the suggestions!

I've been kind of fiddling around with Xcode and I like how it tells you if something is wrong before even compiling and running it. I think I might just write my text in Xcode and just compile and run with Terminal.

I need to learn eventually, right? :rolleyes:

Well, you already have to learn C - which, besides Objective-C, is one of the ugliest programming languages on the planet in my book. So things can hardly get any worse.

That being said, programmers should know there way around a Unix Shell and the Command Prompt on Windows. The Terminal -- IS -- your friend, on ANY operating system. Embrace it. Love it. It's the thing that gives you much more power than any GUI ever could.

As far as editors go, I won't join the decades-old vi vs Emacs debate. On Linux, I usually use "joe", which uses good-old Wordstar-compatible key bindings. That's something most of you probably never have even heard of, and if so, it probably was in a history lesson. I grew up with Wordstar on CP/M and DOS. (And SPF/PC for that matter.)

On a Mac, I'd use BBEdit. The editor comes with command line tools so that you can type bbedit myprogram.c in the Terminal and edit your file comfortably in GUI mode. TextWrangler is the "free" version of BBEdit, but I don't know if it also supports command line tools. If not, BBEdit is worth the money and probably one of the best editors out there.

On Windows, I recommend the Open Source editor "Notepad++". On Linux, Gedit is a good choice. Or Geany.

Why am I talking about multiple platforms here? Because you want to learn how to program. In C. That's a language that many people have called "portable Assembler". It was designed to work well with any platform. So you should do yourself a favor, download VirtualBox and install Windows and Linux in virtual machines and also play with the C compilers there. (And Python, since you've already mentioned it.)

If you want to use an IDE, stick to multi-platform monsters like Eclipse or Netbeans. Yes, both are written in Java. That's why they run everywhere. They're both free. That's why everybody is using them.

But frankly speaking, I'm also in the club of people who would advice you against using a full blown IDE. They only add to the complexity and that doesn't do you any favors when you're still learning how to walk. Things like BBEdit/TextWrangler or Notepad++ already offer more than you will actually need.

Keep it simple and try to have some fun with the stuff that you learn.
 

robvas

macrumors 68040
Mar 29, 2009
3,240
629
USA
There's a book by Apress out there called 'C programming on the Mac' and it covers exactly what you're talking about. Those are the black/yellow books with the fruits on the cover.

Not sure if it covers the latest version of Xcode, though.
 

blackenedheart

macrumors newbie
Sep 3, 2013
6
0
There is nothing wrong with learning in XCODE 4. Just learn how to call NSLog and call your C functions from that... NSLog is a great way to see what your code is doing.

XCODE 4 is a great product and it is very powerful. That being said, you should learn Objective-C and focus less on C. Overall I think the Objective-C classes are very powerful and easy to use once you learn them.
 

Qaanol

macrumors 6502a
Jun 21, 2010
571
11
There is nothing wrong with learning in XCODE 4. Just learn how to call NSLog and call your C functions from that... NSLog is a great way to see what your code is doing.

printf

If you are programming in C, learn to use printf

printf is a great way to see what your code is doing
 

devilofspades

macrumors member
Jul 20, 2011
76
0
Well, you already have to learn C - which, besides Objective-C, is one of the ugliest programming languages on the planet in my book. So things can hardly get any worse...


...Why am I talking about multiple platforms here? Because you want to learn how to program. In C. That's a language that many people have called "portable Assembler". It was designed to work well with any platform. So you should do yourself a favor, download VirtualBox and install Windows and Linux in virtual machines and also play with the C compilers there. (And Python, since you've already mentioned it.)

If you want to use an IDE, stick to multi-platform monsters like Eclipse or Netbeans. Yes, both are written in Java. That's why they run everywhere. They're both free. That's why everybody is using them.

But frankly speaking, I'm also in the club of people who would advice you against using a full blown IDE. They only add to the complexity and that doesn't do you any favors when you're still learning how to walk. Things like BBEdit/TextWrangler or Notepad++ already offer more than you will actually need.

Keep it simple and try to have some fun with the stuff that you learn.

i would disagree with this whole heartedly. i won't get into the great debate over objective-c vs other oop laguages. personally i think the syntax and eligance of objective-c is second to none. i will tell you this, objective-c is c. unlike say c#, you can actually use pure c code along side objective-c code, and this is actually quite common. lower level apple apis are actually c based and have little to no objective-c in them. so by all means learn as much about c simply for the sake of knowing whats going on under the hood, and down the road grappling with more complex apple api.

if you are new to learning a language, one of the worst and most frustrting things when something goes wrong that has nothing to do with what you are learning. installing compilers, libraries, etc can all distract and get in the way of doing work. i am not saying down the road it is not good to learn, but just getting started, xcode is a canned turnkey purpose built platform for the mac that "just works". i mean windows doesn't even have a native c compiler.

for practicing c (or even c++, yes xcode does c++) using the "command line utility" template is your friend. this is your jumping off point, to just start typing code and seeing what happens. this is going to be purley text based in a console window with console output, but thats basically what c was for. unix terminals with no gui.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.