12 Replies Latest reply: Jan 1, 2014 11:15 AM by VikingOSX
milleja46 Level 1 Level 1 (0 points)

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...

  • Frank Caggiano Level 7 Level 7 (25,715 points)

    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

  • etresoft Level 7 Level 7 (26,550 points)

    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.

  • Keith Barkley Level 5 Level 5 (5,650 points)

    From the first chapter of K&R:

     

    "[Getting the first program to compile and run] is the big hurdle; to leap over it you have to be able to create the program text somewhere, compile it succesfully, load it, run it, and find out where the output went. With these mechanical details mastered, everything else is comparatively easy."

  • Frank Caggiano Level 7 Level 7 (25,715 points)

    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

  • milleja46 Level 1 Level 1 (0 points)

    I know but I already bought this book and a obj c book awhile back just haven't had the time for it...especially don't have time for it when I just happen to leave it at my mom's house when I might really be able to read it again XD

  • sl1e Level 1 Level 1 (0 points)

    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.

  • etresoft Level 7 Level 7 (26,550 points)

    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.

  • sl1e Level 1 Level 1 (0 points)

    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?

  • etresoft Level 7 Level 7 (26,550 points)

     

    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.

  • sl1e Level 1 Level 1 (0 points)

    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,

  • etresoft Level 7 Level 7 (26,550 points)

    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.

  • VikingOSX Level 6 Level 6 (10,170 points)

    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.