stdin read

J

jason_box

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;
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top