Newbie needing simple help

This is a discussion on Newbie needing simple help within the C Programming forums, part of the General Programming Boards category; I am a hardware engineer teaching myself C from the K&R second edition bible to allow me to do some ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Newbie needing simple help

    I am a hardware engineer teaching myself C from the K&R second edition bible to allow me to do some basic low level testing of my hw before handing it over to the sw guys.

    I have downloaded MinGW to use on my pc and have added MinGW\bin to my environment variables. i have created a few wee bits of code from chapter 1 that have ran fine from my windows command prompt but am having problems with EOF.

    the simple code i am running is:

    Code:
    #include <stdio.h>
    
    main()
    {
       int c;
       
       while ((c = getchar()) != EOF)
          putchar(c);
    }
    I get the warning when i compile : no newline at end of file. as i am only putting in characters from the keyboard as oppose to a file, how do i get around this.

    Ex1_6 in the book asks me to verify that EOF = 0 or 1, however, entering this does not exit the program ( i also know that the value for EOF = -1 but entering this value does not exit the program either - is this an ANSCII thing)

    Its a simple beginner problem, but one i would like to get to the bottom of none the less.

    Any help would be greatly appreciated.

    cheers in advance, gems

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You hit enter at the end to make sure there's a blank line at the bottom of the file.

    On Windows, EOF is Ctrl-Z.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    2
    Nice one, thanks for that - ctrl Z worked a treat.

    cheers dear, gems

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MFC newbie --- simple problem
    By gemini_shooter in forum Windows Programming
    Replies: 3
    Last Post: 04-03-2006, 04:17 PM
  2. Newbie: Huge EXE files for simple programs - why?
    By Dominic in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 10-11-2002, 04:07 PM
  3. Simple cout query from a newbie
    By Chewbacca in forum C++ Programming
    Replies: 4
    Last Post: 09-08-2002, 07:48 AM
  4. Need some really simple help (complete Linux newbie)
    By Hannwaas in forum Linux Programming
    Replies: 11
    Last Post: 12-10-2001, 02:16 PM
  5. Im a Newbie with a graphics design problem for my simple game
    By Robert_Ingleby in forum C++ Programming
    Replies: 1
    Last Post: 11-23-2001, 05:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21