Thread: Trying to program ANSI C in Xcode 6 - Brand New

  1. #1
    Registered User
    Join Date
    Nov 2014
    Posts
    16

    Trying to program ANSI C in Xcode 6 - Brand New

    Hi, I'm brand new to programming. I ordered a book online "The C Programming Language" -2nd Edition ANSI C.

    I downloaded Xcode 6 as a compiler.

    In the beginning with the really simple programs my programs were running successfully, although the code didn't always exactly match what was in the book.

    Then I moved on and doing programs that make use of character counting and line counting I am not getting the correct output.

    Is this due to the compiler not recognizing the ANSI C? I am brand new to this--is there a way to configure to the compiler to recognize ANSI C? My goal is just to be able to get the compiler to recognize what I'm doing so that the programs run successfully. Should I just get a new book and start somewhere else?

    Any help or recommendations are greatly appreciated.

    Thank you for your help.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    I'm using Xcode 6 as well and have not seen any problem with it yet.
    What code exactly are you not seeing work right?

  3. #3
    Registered User
    Join Date
    Nov 2014
    Posts
    16
    hey thanks for getting back to me...
    well I did one program that just matched the character input that I put in and reprinted it. (This program inputted and outputted successfully).

    Then I moved on to this program, which I just copied from the book and it said it should count characters. I'm able to input characters in the Debug test area, but I get no output that counts the characters... just blank output... assuming that is what the program is supposed to do (count characters as a # display)... I just copied it straight from the book several times now... assuming I copied everything correctly here it is...

    Code:
    #include <stdio.h>
    
    
    int main(int argc, const char * argv[]) {
        long nc;
        
        nc = 0;
        while (getchar() != EOF)
            ++nc;
        printf("%ld\n", nc);
        
    }

  4. #4
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by EricRoberts View Post
    hey thanks for getting back to me...
    well I did one program that just matched the character input that I put in and reprinted it. (This program inputted and outputted successfully).

    Then I moved on to this program, which I just copied from the book and it said it should count characters. I'm able to input characters in the Debug test area, but I get no output that counts the characters... just blank output... assuming that is what the program is supposed to do (count characters as a # display)... I just copied it straight from the book several times now... assuming I copied everything correctly here it is...

    Code:
    #include <stdio.h>
    
    
    int main(int argc, const char * argv[]) {
        long nc;
        
        nc = 0;
        while (getchar() != EOF)
            ++nc;
        printf("%ld\n", nc);
        
    }
    You could just have started a new thread but anyhow nevermind

    Are you entering the end of file key combination for your particular operating system, for instance its it Ctrl + d on linux?

  5. #5
    Registered User
    Join Date
    Nov 2014
    Posts
    16
    Apparently that's what I needed to do, Ctrl + D. I am using Mac OS X 10.9.5. I had no idea what the End of File Key command was.

    On the previous application that just re-printed a string of characters, I was just hitting enter and that was prompting the program to reprint the characters, despite making reference to the EOF value. I never needed to enter this key combination previously, though I wasn't quite sure how to get the program to stop without hitting the stop test button.

    I would have never figured that out. Thank you for your help.

    How would I have known where to find the end of file key combination for my particular operating system? A quick search in google isn't returning many results.

    Thanks for your help.

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    Quote Originally Posted by EricRoberts View Post
    How would I have known where to find the end of file key combination for my particular operating system? A quick search in google isn't returning many results.
    You could Google "OSX EOF"

  7. #7
    Registered User
    Join Date
    Nov 2014
    Posts
    16
    Yeah, that did turn up results. The whole End of File Concept is a little bit foreign to me at this point--with just the book I am using now I would not have known EOF even required a key command to end the program or produce results. Maybe it comes in a later chapter.

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    In the examples that are getting input from stdin as opposed to a file, it's better to just look for '\n'. The newline character that comes from hitting return.
    That way you don't have to enter ctrl + d.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help with arrays and argv in ANSI C program
    By noobneedhelp in forum C Programming
    Replies: 1
    Last Post: 03-05-2013, 10:55 PM
  2. Help with Xcode
    By Zach Sisk in forum C++ Programming
    Replies: 2
    Last Post: 09-26-2012, 05:29 AM
  3. Brand New to C; First Program and a Couple of Questions
    By thepsionicstorm in forum C Programming
    Replies: 52
    Last Post: 09-18-2012, 11:10 PM
  4. mac os x xcode
    By magus2500x in forum C++ Programming
    Replies: 2
    Last Post: 11-03-2005, 12:12 AM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM