Re: Redirecting input from file



"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

.



Relevant Pages

  • Re: fscanf problem
    ... Here is the new seg of code (the input file ... int dum,year,l; ... fputs("Problems reading lead-in of line\n", ... stderr);} /* Some output to make sure we did it right */ ...
    (comp.lang.c)
  • Re: Rookie Student C++ Array question (reading from a file)
    ... int main ... // open input file ... That's your overall plan. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Problems with CLAPACK SVD routines on OS X
    ... column by column (that is what Fortran routines expect). ... Let the first line of your input file be two number: ... int main{ ... Mac OS BLAS parameter error in DGESDD, parameter #0,, is ...
    (sci.math.num-analysis)
  • Re: Sed question (insert newline at specific points)
    ... since I have to use it for a database review. ... blank line in front of every line int he file that starts with a "Z". ... The input file (approx 26,000 lines, each "Z card" indicates a new ... What did I do wrong in the sed command? ...
    (comp.unix.shell)