Results 1 to 4 of 4
  1. #1


    Member Since
    Aug 03, 2009
    Posts
    2
    Need help working with basic C in xcode
    Alright im new to both C and xcode right now, im looking for a bit of help.
    Im trying to learn C right now using "the C programming language" book. I am trying to work though the examples, and im still trying to work out the kinks before I really get into it.

    when I open a new project and use the standard tool it offers this code for the hello world program

    Code:
    #include <stdio.h>
    int main ()
    {
        printf("Hello, World!");
    	return 0;
    }
    this works fine and builds with no warnings, however when I try the example in the book im learning from, written by the people who made the language, I get errors during the build

    Code:
    #include <stdio.h>
    main ()
    {
        printf("Hello, World!");
    }
    now from a programming point of view I understand what the errors are telling me. My question is why does xcode seems to be using different rules while compiling then what I am expecting to see, and whats in the book?

    Also iv noticed both these programs will print if i open them in "console", and it will also run with the same result if I remove the \n, which I definitely cant explain.

  2. #2

    xstep's Avatar
    Member Since
    Jun 25, 2005
    Location
    On the road
    Posts
    3,231
    Specs:
    2011 MBP, i7, 16GB RAM, MBP 2.16Ghz Core Duo, 2GB ram, Dual 867Mhz MDD, 1.75GB ram, ATI 9800 Pro vid
    Is the warning "warning: return type defaults to 'int'"?

    When code or scripts are run from the command line, they are expected to return an 'int' value relating to success or some failure. The compiler seems to be insisting on it. I would consider that a good thing. By the way, I tried using 'void' instead and the compiler warned me I wasn't using an 'int' value.

    Perhaps the version of the book isn't up to date on this, has excluded the information for brevity, or the newer compiler is just being helpful. The latest version of that book is 11 years old. A lot has happened in compiler design since then.

    As for the '\n'. That is simply a line feed. Removing it will will do no harm here. On the command line the cursor will be at the end of the period if you remove that token. The would mean another print line would start printing at that location.
    CameraTime - Time lapse photography for novice and advanced users.

    When asking questions, post the version of your software. You'll receive better answers.

    Please post your results to the thread as it is good feedback.

  3. #3

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Location
    Toronto
    Posts
    19,782
    Specs:
    2012 13" MBP (2.5 i5, 8GB)
    Quote Originally Posted by xstep View Post
    As for the '\n'. That is simply a line feed. Removing it will will do no harm here. On the command line the cursor will be at the end of the period if you remove that token. The would mean another print line would start printing at that location.
    Not that this is a bad explanation (it's quite good in fact) but if you're like me, examples help a great deal.

    Note that before I show an example, my examples are in Python so ignore the fact that my code looks different. I'm just trying to illustrate what the "\n" does. So, let's say I execute the following command:
    Code:
    print("Hello World!")
    Executing that will print Hello World! to the screen. Now, if I change this code to include "\n", the output will put what I include after it on a new line. So, if I execute the following:
    Code:
    print("Hello\nWorld!")
    the output looks like this:
    Hello
    World!


    Hope that helps.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

  4. #4

    D3v1L80Y's Avatar
    Member Since
    Feb 02, 2004
    Location
    PA
    Posts
    12,456
    Specs:
    MacBook
    Thread closed due to high spammer activity.

    Please continue discussion in PM.
    __________________________________________________
    Posting and YOU|Forum Community Guidelines|The Apple Product Cycle|Forum Courtesy

    mac: a waterproof raincoat made of rubberized fabric
    MAC: a data communication protocol sub-layer, also known as the Media Access Control
    Mac: a brand name which covers several lines of personal computers designed, developed, and marketed by Apple Inc.


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. New to Xcode and mac development, need basic help
    By drumvudu in forum OS X - Development and Darwin
    Replies: 3
    Last Post: 07-19-2014, 09:33 PM
  2. Basic info on Xcode compilers (C++)
    By Annettest in forum OS X - Operating System
    Replies: 10
    Last Post: 08-03-2010, 04:51 PM
  3. Anyone know the basic code difference between VS and XCode?
    By SapAuthor in forum OS X - Development and Darwin
    Replies: 2
    Last Post: 09-28-2009, 03:18 PM
  4. Help!! Incredibly basic Xcode Tools Question
    By pdcom in forum OS X - Development and Darwin
    Replies: 1
    Last Post: 08-26-2008, 04:40 PM
  5. Programming basic C in Xcode
    By DrQuincy in forum OS X - Development and Darwin
    Replies: 4
    Last Post: 01-16-2008, 04:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •