473,320 Members | 1,977 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

stdin read

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.

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5. int c, nc = 0, nl = 0;
  6.  
  7. while ( (c = getchar()) != EOF )
  8. {
  9. nc++;
  10. if (c == '\n') nl++;
  11. }
  12.  
  13. printf("Number of characters = %d, number of lines = %d\n", nc,
  14. nl);
  15.  
  16. return 0;
  17. }
  18.  
Apr 26 '06 #1
1 2499
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.

Expand|Select|Wrap|Line Numbers
  •  
  • <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>

    Apr 26 '06 #2

    This thread has been closed and replies have been disabled. Please start a new discussion.

    Similar topics

    9
    by: It's me | last post by:
    Why do I get an "AttributeError: read" message when I do: import sys r=sys.stdin.read() ?? I've tried: r=sys.stdin.read(80)
    2
    by: Stelios G. Sfakianakis | last post by:
    Hello, I am using php 4.2.2 in Red Hat 9.0 with apache 2.0.40 I try to build a php script that accepts POST requests that contain multimedia data and shoves them in a MySQL database. My problem is...
    3
    by: Harayasu | last post by:
    Hi, Using fgets() I can read from stdin and with fputs() I can write to stdout. Now I have two programs, one writing to stdin and the other one reading from stdin. And I would like the second...
    6
    by: Charlie Zender | last post by:
    Hi, I have a program which takes the output filename argument from stdin. Once the program knows the output filename, it tries to open it. If the output file exists, the program asks the user to...
    11
    by: David Warner | last post by:
    Greetings! I need to write some C code that will decide between either reading from stdin or take a file name from argv and process it. The program needs to work like all of the typical unix...
    8
    by: orium69 | last post by:
    Hi! how could i know if it was written something in stdin since the last time i read it? Tks...
    1
    by: asdsd sir | last post by:
    Hi!I'm new in Python and i'd like to ask some general questions about stdin,stdout... Firstly... if we type like something like : cat "file.txt"|python somefile.py #somefile.py import sys
    2
    by: Dmitry Anikin | last post by:
    I want to read stdin in chunks of fixed size until EOF I want to be able (also) to supply data interactively in console window and then to hit Ctrl+Z when finished So what I do is: while True:...
    31
    by: Nikos Chantziaras | last post by:
    Hello. Is there a way to check if the current process has an stdin handle? In the win32 API, one can do: _eof(_fileno(stdin)) Crucial here is that the above doesn't block. Is there a...
    16
    by: fbertasso | last post by:
    Hi, I´m opening stdin to get a file and pass it through a pipe. razor=popen ("/var/qmail/bin/razor-check -home=/var/qmail/razor", "w"); while( (ret=fread(linha,1,sizeof(linha),stdin) ) 0 ) {...
    0
    by: DolphinDB | last post by:
    Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
    1
    isladogs
    by: isladogs | last post by:
    The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
    0
    by: Vimpel783 | last post by:
    Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
    0
    by: ArrayDB | last post by:
    The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
    1
    by: PapaRatzi | last post by:
    Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
    0
    by: CloudSolutions | last post by:
    Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
    0
    by: af34tf | last post by:
    Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
    0
    by: Faith0G | last post by:
    I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
    0
    isladogs
    by: isladogs | last post by:
    The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

    By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

    To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.