arrays - Reading in a list of numbers from a file C -


i trying read in list of numbers file array using scanf. print out array.

the list composed of on thousand numbers example looks this.

70.3 71.5 70.1 71.1 71.8 71.6 72.0 72.0 71.8 

i have but, prints out list of incomprehensible numbers.

int main () {  file *temp; temp = fopen("temp.txt", "r"); int readings[2881]; int temps;      if (!temp)     {         printf("cannot open file!\n");         return 0;     }  (temps = 0; temps < 2881; temps++) {     fscanf (temp, "%d", &readings[temps]); }  (temps = 0; temps < 2881; temps++) {     printf("the readings %d\n", readings[temps]); }  fclose(temp);  return 0; } 

what doing wrong?

you using %d when should using %f, , declaring readings[] double.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -