Re: Redirecting input from file
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Thu, 05 Jul 2007 11:35:28 -0400
"dmoran21@xxxxxxx" wrote:
Here is my code as of now, as well as an input file and my output.
I am aware that I've got more error proofing to do, but this is
what I have right now.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
/* Variable Declarations */
To start with, control your indentation. 3 spaces is enough.
Don't use tabs for Usenet display.
const int arraylength = 5000;
const int exiterrorcode = -1;
int count = 0;
int condition = 1;
float* precipvals = (float*)NULL;
float* precip3hrs = (float*)NULL;
long* date = (long*)NULL;
The above casts are unnecessary, and only serve to hide possible
errors. This is not C++.
FILE *fpin;
FILE *fpout;
fpin = fopen(argv[1],"r");
fpout = fopen(argv[2],"w");
if(fpin == NULL || fpout == NULL) {
printf("Insufficient arguments\n");
exit(exiterrorcode);
}
I believe passing NULL to fopen results in undefined behaviour.
Use argc.
/* Array Allocation */
precipvals = (float*)malloc(sizeof(float) * arraylength);
precip3hrs = (float*)malloc(sizeof(float) * arraylength);
date = (long*)malloc(sizeof(long) * arraylength);
Again, the casts are unnecessary etc.
/* Calculation Section */
while(condition != EOF) {
condition = fscanf(fpin,"%ld,%f", &date[count],
&precipvals[count]);
Here unless 'condition' is 2 fscanf failed. I also gave up
following the code.
--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>
cbfalconer at maineline dot net
--
Posted via a free Usenet account from http://www.teranews.com
.
- References:
- Re: Redirecting input from file
- From: dmoran21@xxxxxxx
- Re: Redirecting input from file
- From: CBFalconer
- Re: Redirecting input from file
- From: dmoran21@xxxxxxx
- Re: Redirecting input from file
- From: dmoran21@xxxxxxx
- Re: Redirecting input from file
- Prev by Date: Re: Does *&s1 refer to the first member of structure variable s1
- Next by Date: Re: help w/ c/c++ problem
- Previous by thread: Re: Redirecting input from file
- Next by thread: Re: Redirecting input from file
- Index(es):
Relevant Pages
|