Thread: beginner's question

  1. #1
    Registered User
    Join Date
    May 2010

    beginner's question

    I just started learning C and I ran into one problem.

    I am using "The C Programming Language" from Brian Kernighan and Dennis Ritchie as a learning material so I am following the examples in that book.

    The problem is with the following programme:

    #include <stdio.h>
    	int c, nl;
    	nl = 0;
    	while ((c=getchar()) !=EOF)
    		if (c == '\n')
    	printf ("%d\n", nl);
    Now, it should give me, as a result, the number of lines in which I typed something. The problem is, when I press Ctrl+C, the programme ends without printing the last line of code.

    Exactly the same problem I encountered with character count.

    The question is probably stupid, but as I said, I just started.

    Any ideas?

    P.S. I am using Geany as IDE. I tried compiling it outside of Geany, with

    cc -c line.c
    cc -o line line.o
    and then running it with

    but no help.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Ctrl+C will end the program. If you want to send EOF, try Ctrl+D (*nix) or Ctrl+Z twice (Windows).

  3. #3
    Registered User
    Join Date
    May 2010
    As I said, probably stupid question .

    Anyway, thanks a lot. Ctrl-d works just fine..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner's Question on QT
    By unix7777 in forum C++ Programming
    Replies: 1
    Last Post: 11-30-2008, 05:53 PM
  2. beginner's question :D
    By kingliaho in forum C Programming
    Replies: 5
    Last Post: 10-17-2008, 05:20 PM
  3. beginner's question about C
    By Roberto Llovera in forum C Programming
    Replies: 5
    Last Post: 02-26-2004, 05:14 PM
  4. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM