Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > stdin read

Reply
Thread Tools

stdin read

 
 
jason_box
Guest
Posts: n/a
 
      04-26-2006
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;
}
 
Reply With Quote
 
 
 
 
Vladimir Oka
Guest
Posts: n/a
 
      04-26-2006
jason_box opined:

Posting the same question every 15 minutes only *reduces* the
probability that it will be answered. This is Usenet, an asynchronous
medium, not a message board.

> 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:
  <snip line/char counting code (most likely) from K&R>

> 


A clever ploy, this: Copying some code only vaguely related to the
(homework) problem at hand.

I suggest you go back to your textbook and look up arrays, loops, and
input/output functions. I'd suggest `fgets()` and `sscanf()`, although
plain `scanf()` is probably OK if you're only dealing with numbers.

--
"I'd crawl over an acre of 'Visual This++' and 'Integrated Development
That' to get to gcc, Emacs, and gdb. Thank you."
(By Vance Petree, Virginia Power)

<http://clc-wiki.net/wiki/Introduction_to_comp.lang.c>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
peek at stdin, flush stdin Johnathan Doe C Programming 5 05-17-2013 04:30 PM
How to pass stdin of a C++ program to the stdin of a process createdwith ShellExecute() Ben C Programming 2 08-29-2009 09:47 PM
STDIN, OUT, ERR and $stdin, out, err - Differences? Terry Cooper Ruby 7 06-09-2009 05:48 AM
Reading from stdin then launching a program that reads from stdin strange behaviour Stefano Sabatini Perl Misc 6 07-29-2007 10:38 PM
Reading stdin once confuses second stdin read Charlie Zender C Programming 6 06-21-2004 01:39 PM



Advertisments