#include<stdio.h>
#include<stdlib.h>
int main()
{
int block[100];
int i = 0;
FILE *fp;
fp = fopen("blockage.dat","r");
if (fp != NULL){
while( !feof(fp) )
{
fscanf(fp,"%d",&block[i++]);
}
}
fclose(fp);
return 0;
}
My blockage.dat file looks like this:
3.712e+05
4.265e+05
5.345e+05
....
The numbers are arranged row wise. So my C program is stuck in the first loop itself. How do I sort this ? How do I ensure that it goes to the next line ?
Where is
i
declared in your program?Set i to 0.
The file contains floating type data. So your array should be
Then do
Depending on the values which you are reading you declare your array with
double
orlong double
type.