stdin read

Discussion in 'C Programming' started by jason_box, Apr 26, 2006.

  1. jason_box

    jason_box Guest

    I'm trying to parse a data file that has two colums, both columns
    should contain numerical values and I would like them to be stored that
    way for now into two seperate arrays. I was wondering whats the best
    way of doing this?

    file:

    112 56
    344 3
    233 9


    This simple program just counts the number of characters and line that
    I pipe into the program and I was wondering how to take it to the next
    step.

    Code:
    #include <stdio.h>
    
    int main()
    {
        int c, nc = 0, nl = 0;
    
        while ( (c = getchar()) != EOF )
        {
        nc++;
        if (c == '\n') nl++;
        }
    
        printf("Number of characters = %d, number of lines = %d\n", nc,
    nl);
    
        return 0;
    }
    
     
    jason_box, Apr 26, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Johnathan Doe

    peek at stdin, flush stdin

    Johnathan Doe, May 15, 2004, in forum: C Programming
    Replies:
    5
    Views:
    25,214
    Chatoyer
    May 17, 2013
  2. Charlie Zender

    Reading stdin once confuses second stdin read

    Charlie Zender, Jun 19, 2004, in forum: C Programming
    Replies:
    6
    Views:
    803
    Dan Pop
    Jun 21, 2004
  3. Ben
    Replies:
    2
    Views:
    1,363
    jacob navia
    Aug 29, 2009
  4. Terry Cooper
    Replies:
    7
    Views:
    433
    Janos Sebok
    Jun 9, 2009
  5. Stefano Sabatini
    Replies:
    6
    Views:
    303
    Stefano Sabatini
    Jul 29, 2007
Loading...

Share This Page