473,382 Members | 1,720 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,382 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 2501
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 ) {...
    1
    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: 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...
    0
    by: taylorcarr | last post by:
    A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
    0
    by: aa123db | last post by:
    Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
    0
    by: ryjfgjl | last post by:
    If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
    0
    by: emmanuelkatto | last post by:
    Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
    1
    by: nemocccc | last post by:
    hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
    1
    by: Sonnysonu | last post by:
    This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

    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.