Hello C programming gurus! I am attempting to read in a file that has 4128 sets of 21 numbers separated by commas and write it into an array. I now know that in order to use fseek, I have to make my array a character array, but I need my function to read in decimals (ex: 0.172635). I'm reading in 0.102598,0.000000,0.000000,0.000000,0.000000,0.307 793,0.000000,0.410391,0.102598,0.000000,0.102598,0 .102598,0.000000,0.000000,0.102598,0.102598,0.8207 83,0.000000,0.000000,0.000000,0.000000 and keep getting numbers like 48 49 50...etc. here is my code, what am I doing wrong?
Code:
void CSread(char filename[100], char array[22], char array2[22], unsigned int arraysize)
{
char genename[32];
double temp = 0;
FILE *CSfile;
CSfile = fopen(filename, "r");
if ( CSfile == NULL )
{
perror ( "Unable to open file" );
exit ( EXIT_FAILURE );
}
fseek(CSfile, 0, SEEK_SET);
fgets(array, 21, CSfile);
printf("The values of the first array are: ");
for (int i=0; i < 22; i++)
{
printf("%d ",array[i]);
}
printf("\n");
fseek(CSfile, 21, SEEK_SET);
fgets(array2, 21, CSfile);
printf("The values of the second array are: ");
for (int j=0; j < 22; j++)
{
printf("%d ",array2[j]);
}
printf("\n");