Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Aug 26, 2013, 12:50 PM   #1
Preston019
macrumors newbie
 
Join Date: Dec 2012
Programming using C

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
Preston019 is offline   0 Reply With Quote
Old Aug 26, 2013, 02:11 PM   #2
djholman
macrumors newbie
 
Join Date: Jul 2013
If you want to program in C your FIRST resort should be the terminal and a program called vi.
djholman is offline   2 Reply With Quote
Old Aug 26, 2013, 05:16 PM   #3
ravenvii
macrumors 604
 
ravenvii's Avatar
 
Join Date: Mar 2004
Location: Melenkurion Skyweir
I write C in Vim and run with the terminal.
__________________
59 6F 75 20 73 70 6F 6F 6E 79 20 62 61 72 64 21
ravenvii is offline   0 Reply With Quote
Old Aug 26, 2013, 05:59 PM   #4
eoblaed
macrumors 6502
 
Join Date: Apr 2010
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.
eoblaed is offline   0 Reply With Quote
Old Aug 26, 2013, 08:09 PM   #5
unterrible
macrumors newbie
 
Join Date: Aug 2013
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.
unterrible is offline   0 Reply With Quote
Old Aug 26, 2013, 08:45 PM   #6
Watabou
macrumors 68030
 
Watabou's Avatar
 
Join Date: Feb 2008
Location: United States
Quote:
Originally Posted by djholman View Post
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.
__________________
Haswell 15" rMBP (2.3Ghz, 16GB, 750M GT) | iPhone 5 | Check out Lyrical on the MAS! | Last.fm

Last edited by Watabou; Aug 26, 2013 at 08:52 PM.
Watabou is offline   0 Reply With Quote
Old Aug 26, 2013, 10:42 PM   #7
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
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.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   1 Reply With Quote
Old Aug 27, 2013, 11:28 AM   #8
ravenvii
macrumors 604
 
ravenvii's Avatar
 
Join Date: Mar 2004
Location: Melenkurion Skyweir
To the above, when I said I use Vim, I actually meant MacVim. I know, I know, a sinful omission, I apologize.

Though the recommendation for Sublime Text is a very good one -- I really like it as well.
__________________
59 6F 75 20 73 70 6F 6F 6E 79 20 62 61 72 64 21
ravenvii is offline   0 Reply With Quote
Old Aug 27, 2013, 02:52 PM   #9
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: 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 by robvas; Aug 27, 2013 at 06:23 PM.
robvas is offline   0 Reply With Quote
Old Aug 27, 2013, 04:53 PM   #10
ravenvii
macrumors 604
 
ravenvii's Avatar
 
Join Date: Mar 2004
Location: Melenkurion Skyweir
Quote:
Originally Posted by robvas View Post
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.
__________________
59 6F 75 20 73 70 6F 6F 6E 79 20 62 61 72 64 21
ravenvii is offline   0 Reply With Quote
Old Aug 28, 2013, 02:20 PM   #11
firewood
macrumors 603
 
Join Date: Jul 2003
Location: 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.
firewood is offline   0 Reply With Quote
Old Aug 28, 2013, 09:56 PM   #12
Preston019
Thread Starter
macrumors newbie
 
Join Date: Dec 2012
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?
Preston019 is offline   0 Reply With Quote
Old Aug 29, 2013, 05:41 AM   #13
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Preston019 View Post
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?
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.
ArtOfWarfare is offline   0 Reply With Quote
Old Aug 29, 2013, 09:55 AM   #14
Winni
macrumors 68030
 
Winni's Avatar
 
Join Date: Oct 2008
Location: Germany.
Quote:
Originally Posted by Preston019 View Post
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?
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.
__________________
Coming soon: http://endnacht.de.
Winni is offline   0 Reply With Quote
Old Aug 29, 2013, 11:06 AM   #15
robvas
macrumors 68000
 
Join Date: Mar 2009
Location: 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.
robvas is offline   0 Reply With Quote
Old Sep 4, 2013, 07:41 AM   #16
blackenedheart
macrumors newbie
 
Join Date: Sep 2013
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.
blackenedheart is offline   0 Reply With Quote
Old Sep 4, 2013, 05:15 PM   #17
Qaanol
macrumors 6502a
 
Join Date: Jun 2010
Quote:
Originally Posted by blackenedheart View Post
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
Qaanol is offline   0 Reply With Quote
Old Sep 10, 2013, 11:37 AM   #18
ArtOfWarfare
macrumors 603
 
ArtOfWarfare's Avatar
 
Join Date: Nov 2007
Send a message via Skype™ to ArtOfWarfare
Quote:
Originally Posted by Qaanol View Post
printf

If you are programming in C, learn to use printf

printf is a great way to see what your code is doing
NSLog is also C, but you'll need to include different libraries to use it.
__________________
Don't tell me Macs don't last: 2007 iMac, 2007 Mac Mini, 2008 MacBook Air, all Vintage.
(iMac obsoletion: April 28, 2015, MBA: October 14, 2015, Mac Mini: March 9, 2016)
ArtOfWarfare is offline   0 Reply With Quote
Old Sep 24, 2013, 04:44 PM   #19
devilofspades
macrumors member
 
Join Date: Jul 2011
Quote:
Originally Posted by Winni View Post
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.
devilofspades is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mac programming should be more like iOS programming. moonman239 Mac Programming 13 Feb 17, 2014 01:37 PM
Help with C programming. Meitou Mac Programming 2 Sep 21, 2012 01:36 PM
C++ programming jmfel1926 Mac Programming 4 Sep 14, 2012 07:21 PM

Forum Jump

All times are GMT -5. The time now is 09:48 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC