Hi. I'm trying to place the contents of a text file with integers into an array.
But the wrong values are being output to the screen:
any ideas?Code:FILE *fin; char file_name_in[20]= "test.txt"; int int_array[1000],c; /* test to see if file opens */ fin = fopen(file_name_in, "r"); if (fin == NULL){ (void)fprintf(stderr,"Cannot open input file %s\n",file_name_in); } int i=0; while((getc(fin))!=EOF){ fscanf(fin, "%d",&c); int_array[i]= c; i++; } for (i=0;i<=7;i++){ printf("%d",int_array[1]); }



LinkBack URL
About LinkBacks


