Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

How to program in C with xcode and k&r?

Does anyone know how to make a plain c project or even better build/run a file without a project using xcode so that i could do it while reading my k&r book? i'm trying to learn c so i can venture into c++ and obj c later...

Posted on May 5, 2013 5:12 AM

Reply
Question marked as Best reply

Posted on May 7, 2013 7:29 AM

You can use any editor to create the source code and compile from the command line but as you are looking to move on to Objective-C at some point you might as well use this time to learn the Xcode IDE. You'll be happy you did in the long run.


To create a plain C program in Xcode first create a new project and select Command Line Tool as the template in the next window select C as the type.


You can pretty much do everything out of K&R at this point.


good luck


regards


Here is Apples Xcode User Guide


Message was edited by: Frank Caggiano

12 replies
Question marked as Best reply

May 7, 2013 7:29 AM in response to milleja46

You can use any editor to create the source code and compile from the command line but as you are looking to move on to Objective-C at some point you might as well use this time to learn the Xcode IDE. You'll be happy you did in the long run.


To create a plain C program in Xcode first create a new project and select Command Line Tool as the template in the next window select C as the type.


You can pretty much do everything out of K&R at this point.


good luck


regards


Here is Apples Xcode User Guide


Message was edited by: Frank Caggiano

May 7, 2013 9:24 AM in response to milleja46

milleja46 wrote:


Does anyone know how to make a plain c project or even better build/run a file without a project using xcode so that i could do it while reading my k&r book? i'm trying to learn c so i can venture into c++ and obj c later...

Learn and use vi.


Just do "vi HelloWorld.c". You start in "command mode" where you type i to insert, a to add, etc. Type escape to get back to insert mode. If you are going to be a UNIX programmer, knowledge of vi is not optional.


The same goes for the command line. You can compile that program above with:

clang HelloWorld.c

and then run it with ./a.out


The command line, especially pipes, are another essential part of UNIX.


Of course, using the command line is impractical for all but the smallest projects. You will want to progress to Xcode fairly quickly, but if you are learning using K&R, use vi on the command line. K&R would appreciate that.

May 8, 2013 5:08 AM in response to milleja46

One other point, if your goal is to learn Objective-C, while knowing C before can be a help, it isn't absolutely mandatory.


Programming in Objective-C (5th Edition) (Developer's Library) by Kochan starts off right in Objective-C and assumes you have no C background. What C is needed is introduced when it is required, He also ignores the GUI, the place what a lot of new programmers get really lost, and just deals with Objective-C and the Foundation classes.


Something else to think about.


Good luck


regards

Dec 31, 2013 2:14 PM in response to Frank Caggiano

Alright, Well I figured this was an appropriate spot to at this issue. I followed this and I can now start coding k&r C great! However I'm only trying to code using xCode as a last attempt to find a solution to my issue. It seams

-std=c89 is broken on Mavericks.


The title does say K&R and here is the code from example proble 1-16 out of K&R.


You can pretty much do everything out of K&R at this point.


good luck


regards



Here is the paste bin to my code and gcc compile error out put.

http://pastebin.com/054dchWE


This is also the paste bin to my clang out put issue.

http://pastebin.com/hxPyUEGR


If I can give any more information please let me know.

Dec 31, 2013 2:26 PM in response to sl1e

sl1e wrote:


Alright, Well I figured this was an appropriate spot to at this issue.


Not quite. It is always best to start your own question instead of piggy-backing on someone else's question.


I followed this and I can now start coding k&r C great! However I'm only trying to code using xCode as a last attempt to find a solution to my issue. It seams

-std=c89 is broken on Mavericks.



No, c89 is not broken. You are trying to redefine a system function.

Dec 31, 2013 2:40 PM in response to etresoft

Well I was told I could follow everything in K&R from this thread. I was talking to someone over on a c99 irc and they told me it wasn't my fault that K&R C didn't work because of my OS.


Can you point me in the right direction to get this example form the book to work with LLVM or clang.


Or tell me what question I need to ask to start a new thread?

Dec 31, 2013 3:35 PM in response to sl1e


sl1e wrote:


Well I was told I could follow everything in K&R from this thread. I was talking to someone over on a c99 irc and they told me it wasn't my fault that K&R C didn't work because of my OS.


Don't believe what people tell you over IRC.


Can you point me in the right direction to get this example form the book to work with LLVM or clang.


Change all occurrences of "getline" to "mygetline".


Also, you are using gcc with the "-std=c89" option. GCC is officially deprecated on OS X. Use "clang" instead. There is no need to use the "-std=c89" option. Leave it off and let clang tell you what to change so that your code is correct for this century.


Or tell me what question I need to ask to start a new thread?

It is up to you to phrase your questions. The problem is that many questions are pertinent only to a specific timeframe. This thread is only a few months old. The other day, someone resurrected a 2 year-old thread and insulted people because their answers that were correct in 2011 were no longer true. Things change. It isn't 2011, or 1989, anymore.

Dec 31, 2013 4:05 PM in response to etresoft

Thank you that helped a ton, I only replied because the thread was a few months old. I was also told to follow K & R to the T. That is why I was back on using an already defined function.


I have redefined my functions again and am still getting this issue with clang.

http://pastebin.com/hxPyUEGR


When I use the GUI I am getting a break point at while in my defined copy() i'm sure that is just a generational syntax issue for now i'm more trying to get passed the issue I pastebined.


Thanks,

Dec 31, 2013 5:39 PM in response to sl1e

sl1e wrote:


I was also told to follow K & R to the T.

By the same person who told you to blame the OS?


I have redefined my functions again and am still getting this issue with clang.

http://pastebin.com/hxPyUEGR


When I use the GUI I am getting a break point at while in my defined copy() i'm sure that is just a generational syntax issue for now i'm more trying to get passed the issue I pastebined.


I strongly suggest you take a step back, start your own thread, post the code you are using, and the error you are getting. Don't bother setting language versions or verbose output. Use clang.

Jan 1, 2014 11:15 AM in response to milleja46

Learning anything well to the extent that you have functional command, requires a mental and time investment. And if you are serious about your craft, your library won't have one or two books in it either.


Here is a vi cheat sheet, similar to the one I used when self-learning from the first edition of K & R C on a PDP-11/44 and Unix System III.

How to program in C with xcode and k&r?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.