Thread: simple count line program

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    Trinidad & Tobago
    Posts
    43

    simple count line program

    hello everyone,
    i executed this code but the loop never ends because i have no idea what EOF is hence the number of lines that i enter is not printed.
    What do i press to signal EOF when i'm finish entering a suitable number of lines to see if they were counted by the program?(-1,0,1) do not work
    Code:
    #include <stdio.h>
    /* count lines in input */
    main()
    {
    int c, nl;
    nl = 0;
    while ((c = getchar()) != EOF)
    if (c == '\n')
    ++nl;
    printf("%d\n", nl);
    }
    not my code btw
    Last edited by Shinzu911; 05-02-2012 at 11:56 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. checking command line argument count [ac],linux
    By bos1234 in forum C Programming
    Replies: 13
    Last Post: 04-12-2012, 06:15 AM
  2. Replies: 3
    Last Post: 02-21-2011, 10:21 PM
  3. Program to count 1 through 9
    By starwarsyeah in forum C Programming
    Replies: 9
    Last Post: 03-09-2009, 01:35 PM
  4. simple program to count the character not working
    By hitesh1511 in forum C Programming
    Replies: 12
    Last Post: 08-08-2006, 04:13 AM
  5. make line count
    By Ron in forum C Programming
    Replies: 7
    Last Post: 07-09-2006, 09:55 AM