c source code

Bill Brown brown at zorro.cecer.army.mil
Tue Jan 18 10:51:48 EST 1994


"wadada",

Aside from a few syntax errors, there's not really anything wrong with your
C code.  Here's a corrected version:



#include <stdio.h>

main()
{
int c1,c2,c3,a,h,s;
FILE *infile;
float d[5][5][5],t[5][5][5];
int   v1[5][5][5],v2[5][5][5],v3[5][5][5];

a=h=s=2;
if((infile = fopen("test.dat", "r")) == NULL)
{
  fprintf(stderr,"Error opening file");
  exit(1);
}
for(c1=0; c1<a; c1++)
{
  for(c2=0; c2<h; c2++)
  {
    for(c3=0; c3<h; c3++)
    {  /* you were missing this opening brace */
	fscanf(infile,"%d %d %d%f", &v1[c1][c2][c3],&v2[c1][c2][c3],
	    &v3[c1][c2][c3], &d[c1][c2][c3]);

	/* WAS
	 printf("%d %d %d %f",
	     V1[c1][c2][c3],v2[c1][c2][c3],v3[c1][c2][c3];d[c1][c1][c3]);
	*/

	printf("%d %d %d %f\n",
	    v1[c1][c2][c3],v2[c1][c2][c3],v3[c1][c2][c3],d[c1][c2][c3]);

	t[c1][c2][c3]=2*d[c1][c2][c3];
	printf(" %f\n",t[c1][c2][c3]);
	/*this is where the error sets in; t[c1][c2][c3] just comes as
	gabbage */
	/* OK NOW */
    }
  }
}
  fclose(infile);
}

-Bill



More information about the grass-user mailing list