Compiler Problem ?

This is a discussion on Compiler Problem ? within the C Programming forums, part of the General Programming Boards category; I am fairly new to C programming (and computer programming) I am typing examples from "The C Programming Language" book ...

  1. #1
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66

    Compiler Problem ?

    I am fairly new to C programming (and computer programming)
    I am typing examples from "The C Programming Language" book but after i compile in Visual studio and run the programs, i dont get the results that the author explains . To be more specific, i run small word and character count programs like..

    main()
    {
    long nc;
    nc=0;
    while (getchar() != EOF)
    --nc;
    printf("%ld\n", nc);
    }

    and after typing a few words and pressing ENTER nothing
    happens except that i goto a new line. is this normal, or should
    i get a character count ?

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    EOF is only generated at the End Of the File. therefore pressing enter doesn't do that. If you on Windows, try entering your number followed by CTRL+Z, then enter. That should generate EOF.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66
    Sorry for not being clear, but getting out is not the problem. the book says after running this in a Dos window, and type a few words or letters or whatever and press enter, you should get a character count or something. i dont gat anything though. if you complie and run this, you should get a count of some sort.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    It appears that the CTRL+Z method of generating EOF is messing around. Here's a couple of things to do:

    - Redirect input into the program from a file instead of the keyboard. EG c:\prog1 <sometextfile.txt

    - Change the program to have '\n' instead of EOF. This will stop the loop when you press enter.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User Spectrum48k's Avatar
    Join Date
    May 2002
    Posts
    66
    Ok.. nevr mind.. I got it Thanx !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dev-C++ compiler problem
    By GrasshopperEsq in forum C++ Programming
    Replies: 19
    Last Post: 05-08-2008, 03:35 AM
  2. Compiler Problem
    By sitestem in forum C++ Programming
    Replies: 2
    Last Post: 04-11-2004, 04:48 PM
  3. Replies: 5
    Last Post: 12-03-2003, 05:47 PM
  4. Problem with compiler
    By knight543 in forum C++ Programming
    Replies: 4
    Last Post: 02-09-2002, 09:16 PM
  5. Please help me with this compiler problem
    By incognito in forum C++ Programming
    Replies: 1
    Last Post: 01-05-2002, 05:14 PM

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