How to run C code in XCode

Discussion in 'Mac Programming' started by shikha123, Apr 21, 2009.

  1. shikha123 macrumors newbie

    Joined:
    Apr 21, 2009
    #1
    I have a small doubt. I have written a code in C and tried running it on XCode using command line utility's Standard tool. I am able to see the output on console. But, now I want to see the same output on the iphone simulator. So, finally the question, is there an easy way to do this...or do I have to learn about building a GUI for my codes?
     
  2. uaecasher macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #2
    Use Interface Builder (it comes with xCode)
     
  3. shikha123 thread starter macrumors newbie

    Joined:
    Apr 21, 2009
    #3
    Thanks so much... But could you please give some pointers on how to go about the interface builder..? As far as I know, the interface builder can be run only in Objective C. Pardon my little knowledge on the suject :). I am new to Xcode..
     
  4. uaecasher macrumors 65816

    uaecasher

    Joined:
    Jan 29, 2009
    Location:
    Stillwater, OK
    #4
  5. larkost macrumors 6502a

    Joined:
    Oct 13, 2007
    #5
    The problem is that you assume that the iPhone has a command-line interface (like the one in XCode), but it does not. Apple has done this because they want iPhone apps to be easy to use, and interpret that to mean GUI apps.

    So there is not generally a Terminal app to interpret stdout. You are gust going to have to get used to writing GUI apps. You can still just wrap them around your C code, but you should get used to the system, rather than trying to force the iPhone environment to match what you are used to.
     
  6. shikha123 thread starter macrumors newbie

    Joined:
    Apr 21, 2009
    #6
    Hello,

    Thanks for the reply. I do understand that the command line application is not supported by iPhone. But, I have a submission in a few days from now. So, for the time being could you suggest a work around wherein I can use my C Program as an iPhone application i.e the output gets displayed on the simulator rather than console.

    Thanks once again.

    Warm regards,
    Shikha
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    The suggestion I would have is to convert it to an iPhone application by building a single interface in interface builder that has an input field, and an output field. You can then wire up a controller to those two fields, and when you get some input on the input field you can simply run your existing C code to manipulate this data, then set the output field to what you would have printed to the console.

    You may have to turn some C strings into NSStrings and vice-versa, but that isn't too involved.

    -Lee

    Note: I am not sure what your application does, exactly, but something this bare-bones is unlikely to be... let's say, very popular in the app store.
     
  8. shikha123 thread starter macrumors newbie

    Joined:
    Apr 21, 2009
    #8
    Actually, my C code is the implementation of the TCP protocol.It has a client and server program. The client sends the data which is being received by the server. Now the problem is the client( which is just a socket C program) has to run on the iPhone and the server is Mac. Both of them are connected via Wifi.The problem lies with the client program as I need to import it on iPhone. The server part is running ok.
     
  9. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #9
    Getting this to run is quite simple. You'll have to get one of the iPhone sample applications working first. You won't get around learning _some_ Objective C / Cocoa programming to do that. Add an "awakeFromNib" method in the right place, and call your C code from that method. Sockets work just fine both on the simulator and on the real iPhone, so if your code works when server and client run on two different Macs, it should work on Mac and iPhone as well.
     

Share This Page