473,769 Members | 4,909 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

read and write columns

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+linp ut/count;
if ((fpw=fopen("da ta","w"))!=EOF) ;
if ((fpr=fopen("da ta","r"))!=EOF) ;
if ((fscanf(fpr,in put,linput,mean ))==0;
fprintf(fpw,"%d \t%d\t%d\n",inp ut,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.

Bill
Jul 3 '08 #1
63 3265
Bill Cunningham said:
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;
div is a standard C library function prototyped in <stdlib.h>, so this
definition of div "shadows" that function, preventing you from using it.
It is best to avoid using standard C library function names except when
referring to standard C library functions.
double mean=0,linput=0 ;
FILE *fpr, *fpw;
mean=input+linp ut/count;
if ((fpw=fopen("da ta","w"))!=EOF) ;
You have K&R2. Look up fopen's return value on failure. You've been told
about this before, and quite recently too.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #2
On Thu, 03 Jul 2008 00:12:03 GMT, "Bill Cunningham" <no****@nspam.c om>
wrote:
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;
White space is free. Use it make your code readable.
double mean=0,linput=0 ;
FILE *fpr, *fpw;
mean=input+linp ut/count;
What is the value of count? Are you allowed to divide by that value?
if ((fpw=fopen("da ta","w"))!=EOF) ;
Didn't your compiler generate a diagnostic here? What type and range
of EOF? What type of value does fopen return to be stored in fpw? Are
the two in any way compatible.
if ((fpr=fopen("da ta","r"))!=EOF) ;
if ((fscanf(fpr,in put,linput,mean ))==0;
You couldn't figure out that you are missing a right parenthesis here?
What do you expect that superfluous semicolon to do?

What are the arguments to fscanf supposed to be? Other than fpr, do
any of yours meet the criteria?

Admit it, you didn't even try to compile the code.
fprintf(fpw,"%d \t%d\t%d\n",inp ut,input+linput ,mean);
}
What type of argument does %d promise? What are the types of your
arguments.
>
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.
If you don't know how to increment count, you need to start with
programs that are very much more basic than this. Strange that you
didn't have any trouble incrementing input above. OK, so you did have
trouble but at least you knew (lucky guess?) which operator to use.


Remove del for email
** Posted from http://www.teranews.com **
Jul 3 '08 #3
On Jul 3, 5:12 am, "Bill Cunningham" <nos...@nspam.c omwrote:
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+linp ut/count;
What exactly do you mean? input + (linput / count) or (input +
linput) / count. Do you see a divide by zero problem here? Since input
and linput are define as double, your mean equals infinity.
if ((fpw=fopen("da ta","w"))!=EOF) ;
if ((fpr=fopen("da ta","r"))!=EOF) ;
May be next time you should remember fopen returns FILE * and the
error checking is done against NULL.
So if ((fpw = fopen("data", "w")) != NULL);
But heck; even now it is meaning-less(that ;, if you didn't notice).
Check for NULL and then do nothing - just proceed with the code.
if ((fscanf(fpr,in put,linput,mean ))==0;
Again, check for error and do nothing. And this won't compile on any
known compiler(missin g parenthesis).
fprintf(fpw,"%d \t%d\t%d\n",inp ut,input+linput ,mean);
}
input, input + linput are doubles. mean is a double and equals
infinity. %d, if you have a look at the doc, is meant for signed
integers.
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.
I don't know but it looks like to me that you created this mess on
purpose. There are better ways to have fun if that is what you are
trying to have over here.
Jul 3 '08 #4
Barry Schwarz said:
On Thu, 03 Jul 2008 00:12:03 GMT, "Bill Cunningham" <no****@nspam.c om>
wrote:
> 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;

White space is free. Use it make your code readable.
> double mean=0,linput=0 ;
FILE *fpr, *fpw;
mean=input+linp ut/count;

What is the value of count? Are you allowed to divide by that value?
Good spot, Barry. I missed that completely.
> if ((fpw=fopen("da ta","w"))!=EOF) ;

Didn't your compiler generate a diagnostic here?
Just a thought here - Bill Cunningham is a self-confessed slow learner, so
it might be quicker for us and more productive for him if we just point
out the *first* mistake. Maybe over time BC will begin to understand that
he's not going to get help with problem B for so long as his code
continues to exhibit problem A, and he might - just *might* - work out
that eliminating problem A from all his code is therefore a productive
thing for him to do.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #5
On Jul 3, 5:12 am, "Bill Cunningham" <nos...@nspam.c omwrote:
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) {
Though it is legal, naming the parameter the same as your function
name is not a good practice.
Jul 3 '08 #6
On Thu, 03 Jul 2008 04:57:37 +0000, Richard Heathfield posted:
Barry Schwarz said:
>On Thu, 03 Jul 2008 00:12:03 GMT, "Bill Cunningham" <no****@nspam.c om>
wrote:
>> 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;

White space is free. Use it make your code readable.
>> double mean=0,linput=0 ;
FILE *fpr, *fpw;
mean=input+linp ut/count;

What is the value of count? Are you allowed to divide by that value?

Good spot, Barry. I missed that completely.
>> if ((fpw=fopen("da ta","w"))!=EOF) ;

Didn't your compiler generate a diagnostic here?

Just a thought here - Bill Cunningham is a self-confessed slow learner, so
it might be quicker for us and more productive for him if we just point
out the *first* mistake. Maybe over time BC will begin to understand that
he's not going to get help with problem B for so long as his code
continues to exhibit problem A, and he might - just *might* - work out
that eliminating problem A from all his code is therefore a productive
thing for him to do.

I think this idiom is largely unnecessary:
>> if ((fpw=fopen("da ta","w"))!=EOF) ;
If every char you put has to be tested for EOF, then you have a deficient
OS. I gave windows 40 gigs today. It prompts me annoyingly for lack of
hog space.

That the C programming language must be constarined to the average clicker
is a distortion.
--
Ron Ford
Jul 3 '08 #7
Ron Ford said:

<snip>
>

I think this idiom is largely unnecessary:
>>> if ((fpw=fopen("da ta","w"))!=EOF) ;
It isn't an idiom. It's just a bug.

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #8
On Thu, 03 Jul 2008 09:27:48 +0000, Richard Heathfield posted:
Ron Ford said:

<snip>
>>

I think this idiom is largely unnecessary:
>>>> if ((fpw=fopen("da ta","w"))!=EOF) ;

It isn't an idiom. It's just a bug.
When I have to do IO with C, I use safegets, but I don't think that that is
what you mean.

My point was that my OS doesn't say nay to me on a char basis.

I'm curious what you mean.
--
Ron Ford
"Close enough to Texas to feel disinformation. "
Jul 3 '08 #9
Ron Ford said:
On Thu, 03 Jul 2008 09:27:48 +0000, Richard Heathfield posted:
>Ron Ford said:

<snip>
>>>

I think this idiom is largely unnecessary:

> if ((fpw=fopen("da ta","w"))!=EOF) ;

It isn't an idiom. It's just a bug.

When I have to do IO with C, I use safegets, but I don't think that that
is what you mean.

My point was that my OS doesn't say nay to me on a char basis.

I'm curious what you mean.
The fopen function never returns EOF, ever. Since EOF is an int, and since
fopen returns a FILE *, testing the return value of fopen against EOF is
completely pointless. (In this case, the semicolon makes it doubly
pointless.)

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jul 3 '08 #10

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

Similar topics

9
710
by: Kelvin | last post by:
Hi, group: I am intermediate in C programming, basically I programmed in Unix for digital signal processing... Now I need to write a C++ program to read/write the whole volume of a FAT formatted smartmedia card...I can view the raw data in WinHex...now what I want is, in generic C codes to read all the data I see in WinHex...
18
4893
by: jas | last post by:
Hi, I would like to start a new process and be able to read/write from/to it. I have tried things like... import subprocess as sp p = sp.Popen("cmd.exe", stdout=sp.PIPE) p.stdin.write("hostname\n") however, it doesn't seem to work. I think the cmd.exe is catching it.
8
31014
by: Patrik Malmstrm | last post by:
How do I read, write a file binary? I want to open, say, file.exe read it in to the program, then write it out to file2.exe. Like file copy, anyone have a code sample?
1
4883
by: Nadja Schmitt | last post by:
Hi! Is it possible to read/write a *.resx-file? The problem: I'd like to add some more columns to my resource-file, than read the data out of the file and write the data in this file. I tried this with ResourceManager and ResXRessourceReader/ResXRessourceWriter, but it did not work. Is it possible
10
2545
by: Tibby | last post by:
I need to read/write not only text files, but binary as well. It seems like on binary files, it doesn't right the last 10% of the file. -- Thanks --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.538 / Virus Database: 333 - Release Date: 11/10/2003
0
1006
by: jwtulp | last post by:
Hello, I have a question about XmlSerialization. I have a class with a private field called createDate of the type DateTime. In the constructor of my class I use DateTime. Now to create a timestamp that is assigned to the field createDate. Because I want to encapsulate as much as possible of my class data and don't want clients of my class to change the createDate but only read it, I encapsulate the createDate field with a get Property....
0
3867
by: martinmercy2001 | last post by:
Could any body help me with creating a ring buffer class using a string. use memory circular buffer not an IO buffer. just read, write and seek method. Read method should take anumber and return the string. write method should take a string. seek should take a number and return nuthing. use three member variables a buffer itself as a string, read_position, write_position. use >>, << methods. I have tried this code but i need full...
6
7281
by: Ryan Liu | last post by:
Hi, I have some basic question about NetworkStream, can someone explain to me? Thanks a lot in advance! TcpClient has a GetStream() method return a NetworkStream for read and write. I remember there are 2 streams in Java, one for read, one for write. If I just use synchronous Read() and Write() method:
4
4753
by: Bruno | last post by:
Hi! I have big .txt file which i want to read, process and write to another .txt file. I have done script for that, but im having problem with croatian characters (Š,Đ,Ž,Č,Ć). How can I read/write from/to file in utf-8 encoding? I read file with fileinput.input. thanks
0
1825
by: Brian Pinto | last post by:
Im facing a problem with file stream read/write for a usb device. The code works fine on XP (32 bit). but fails to work on Windows 7 (64 bit). I'm successfully past problem of getting the device to enumarate and getting the file handle However the fileStream Read/Write doesn't work I used the managed file stream method i.e first create a handle via native call in overlapped mode. Then use the handle to get a FileStream object and perform...
0
9586
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10043
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7406
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6672
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.