|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
[C] Lettura numeri da file
Salve a tutti, ho il seguente problema: devo leggere dei numeri da un file .dat generato in Fortran(anche se credo non sia importante) che ha la seguente struttura:
37.33 .343 22.87 42.81 1.3 83.35 2900 il mio programmino utilizzato in altre occasioni è: Codice:
int legge_parametri(float tempread[]) { FILE *fdati; int i; if((fdati=fopen(stringa1,"r"))==NULL) printf("\nImpossibile aprire il file"); else { printf("\nParametri.\n"); i=0; while(fscanf(fdati,"%f",&tempread[i])>0) { printf("."); i++; } printf("\n1 - Letti %d parametri.\n",i); } fclose(fdati); return 1; } Codice:
Parametri. ....... 1 - Letti 7 parametri. tempread[1]= 37.330002 tempread[2]= 0.343000 tempread[3]= 22.870001 tempread[4]= 42.810001 tempread[5]= 1.300000 tempread[6]= 83.349998 tempread[7]= 2900.000000 Codice:
... float kappa; ... kappa=37.33; Codice:
warning C4305: '=' : truncation from 'double' to 'float' Ciao
__________________
"May the wind always be at your back and the sun upon your face. And may the wings of destiny carry you aloft to dance with the stars...." |
![]() |
![]() |
![]() |
#2 | |
Senior Member
Iscritto dal: Oct 2007
Città: Padova
Messaggi: 4131
|
Quote:
Codice:
float kappa; ... kappa=37.33f;
__________________
As long as you are basically literate in programming, you should be able to express any logical relationship you understand. If you don’t understand a logical relationship, you can use the attempt to program it as a means to learn about it. (Chris Crawford) |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 11:33.