Re: read and write columns



"Bill Cunningham" <nospam@xxxxxxxxx> writes:
I don't think I can do this without some help or hints. Here is the code
I have.

#include <stdio.h>
#include <stdlib.h>

double input(double input) {
int count=0,div=0;
double mean=0,linput=0;
FILE *fpr, *fpw;
mean=input+linput/count;
if ((fpw=fopen("data","w"))!=EOF);
if ((fpr=fopen("data","r"))!=EOF);
if ((fscanf(fpr,input,linput,mean))==0;
fprintf(fpw,"%d\t%d\t%d\n",input,input+linput,mean);
}

It's very much incomplete. I have two stream open one for reading and one
for writing but the count that I have been speaking of, I don't know how to
increment it.

Look up the word "increment" in your C textbook.

I thought you were going to run your code through "indent" before
posting it.

You have no "main" function.

The code you posted doesn't compile. Did you even try compiling it
before posting?

You attempt to open the same file, "data", for writing and reading,
using two separate streams. This makes no sense.

You have 3 if statements. You don't do anything in any of them. Just
how do you think an if statement works?

Why are you comparing the result of fopen() to EOF? Read the
documentation for fopen(). Don't guess.

You're calling fscanf() with four arguments: a FILE* (good) and three
doubles. Read the documentation for fscanf. For the umpteenth time,
don't guess.

You haven't said what the code is supposed to do. For the umpteenth
time, state the problem you're trying to solve. If you haven't done
that, writing even a single line of code is a waste of time.

This appears to be similar in intent to something that was discussed
at length in another thread, but I'm not going to assume that there's
any correlation; you never offered a decent problem definition in that
thread either.

In the absence of any problem definition, here's a correct program
that meets all the requirements you've stated:

int main(void)
{
}

If you can tell us what functionality is missing from that program,
*maybe* we can start to help you.

But I doubt it.

I honestly think you need to go back a few steps. Pick a simpler
problem to solve. Define the problem clearly in plain English. Then,
and only then, try to write a program to solve the problem. Never
write a call to a library function without first understanding what
arguments the function expects, what result it returns, and what each
and every argument and result means. This requires reading the
documentation.

Get a copy of K&R2 if you don't already have one. Start at the
beginning and work your way through it. Do all the exercises.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.



Relevant Pages

  • Re: Newbie: Accessing usb port in C
    ... > reading and writing and in non-blocking mode use ... > int fd; ...
    (comp.os.linux.development.system)
  • Re: Performance problem when using movaps SSE instruction.
    ... the numbers is necessary before reading, therefore writing preceds the ... execution time is not affected by the writing to the address. ... int vector ...
    (alt.lang.asm)
  • Read-Write hdd sectors
    ... I m writing the Diagnostic code for the HDD. ... Writing the new data into that sectors ... Again reading back the data from the sector ... int ReadSector; ...
    (comp.os.linux.embedded)
  • Re: creating copy of the jar file
    ... writing by #FileOutputStream.write(byte, int, int) ... when readByte returns -1 its the end of your input file ... use the same bytefor reading and writing, ...
    (comp.lang.java.programmer)
  • Re: why not enough lisp libraries?
    ... NET.QUADIUM.LDIF is an LDIF reading and writing library. ... A tarball of version 0.9 of both these libraries, ... PDF documentation for both libraries is included in the tarball. ...
    (comp.lang.lisp)