| 
 | |||||||
| 
 | 
|  | 
|  | 
|  | Strumenti | 
|  18-12-2007, 12:07 | #1 | 
| Senior Member Iscritto dal: Dec 2004 
					Messaggi: 783
				 | 
				
				[C] Leggere file sotto Linux
			 
		Salve a tutti ho scritto un programmino con MS Visual C++ per leggere un file. Successivamente ho eseguito lo stesso listato sotto Linux ma non ottengo lo stesso risultato. Tranne il primo valore del primo vettore tutti gli altri risultano sballati. La riga fondamentale è la seguente che funziona a meraviglia sotto win Codice: while(fscanf(fp,"%LE %LE %LE %LE %LE %LE",&time[i],&mat1[i],....,&matx[i])>0)   Grazie 
				__________________ "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...." | 
|   |   | 
|  18-12-2007, 12:17 | #2 | 
| Senior Member Iscritto dal: Nov 2005 Città: TO 
					Messaggi: 5206
				 | 
		
Ma le varie variabili che ricevono i valori sono di tipo long double?
		 
				__________________ Andrea, SCJP 5 (91%) - SCWCD 5 (94%) | 
|   |   | 
|  18-12-2007, 12:47 | #3 | |
| Senior Member Iscritto dal: Dec 2004 
					Messaggi: 783
				 | Quote: 
 Prima riga del file dati.dat: 0.00000E+00 0.00000E+00 0.36077E+01 0.00000E+00 0.47400E+02 0.39976E+01 0.90246E+00 Codice: while(fscanf(fp,"%E %E %E %E %E %E %E",&temp1[i],...,&temp7[i])>0) Codice: temp[0]= 0.000000E+00 temp[1]= 5.164076E-315 temp[2]= 5.205521E-315 temp[3]= 5.230388E-315 temp[4]= -3.147250E-39 temp[5]= 5.263544E-315 temp[6]= 5.271833E-315 temp[7]= 5.280122E-315 Codice: while(fscanf(fp,"%LE %LE %LE %LE %LE %LE %LE",&temp1[i],...,&temp7[i])>0) Codice: temp[0]= -0.000000E+00 temp[1]= -7.988564E+2863 temp[2]= -7.988564E+2863 temp[3]= -5.991423E+2863 temp[4]= -7.988564E+2863 temp[5]= -4.992853E+2863 temp[6]= -5.991423E+2863 temp[7]= -6.989994E+2863 
				__________________ "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...." | |
|   |   | 
|  18-12-2007, 13:18 | #4 | 
| Senior Member Iscritto dal: Nov 2005 Città: TO 
					Messaggi: 5206
				 | 
		
%E è per un double, %LE è per un long double. long double non è la stessa cosa di double, sono due tipi di dato diversi (dove long double è chiaramente più esteso del double). 
				__________________ Andrea, SCJP 5 (91%) - SCWCD 5 (94%) | 
|   |   | 
|  18-12-2007, 13:35 | #5 | |
| Senior Member Iscritto dal: Dec 2004 
					Messaggi: 783
				 | Quote: 
   Grazie 
				__________________ "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...." | |
|   |   | 
|  18-12-2007, 13:45 | #6 | 
| Senior Member Iscritto dal: Dec 2004 
					Messaggi: 783
				 | 
		Ho provato a dichiarare i vettori come variabili float ed adesso va  . Perche c'è questa differenza con windows  ? Se però volessi utilizzare i double come dovrei fare  ? Grazie Invece di diminuire le domande qui aumentano   
				__________________ "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...." | 
|   |   | 
|  18-12-2007, 13:49 | #7 | 
| Senior Member Iscritto dal: Nov 2005 Città: TO 
					Messaggi: 5206
				 | 
		
Tra l'altro mi sono sbagliato: nelle Xscanf %E è per un float, %lE (l minuscola) è per un double e %LE (L maiuscola) è per un long double. Se hai messo lo specificatore corretto per il tipo di dato delle variabili, non vedo problemi, su Win o Linux che sia (non ho provato, chiaramente). 
				__________________ Andrea, SCJP 5 (91%) - SCWCD 5 (94%) | 
|   |   | 
|  18-12-2007, 14:49 | #8 | |
| Senior Member Iscritto dal: Dec 2004 
					Messaggi: 783
				 | Quote: 
   Ora funziona anche il double con %lE...solo che non mi gira quello con l'allocazione dinamica se utilizzo double al posto di float. Perche?         
				__________________ "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...." | |
|   |   | 
|   | 
| Strumenti | |
| 
 | 
 | 
Tutti gli orari sono GMT +1. Ora sono le: 13:06.









 
		 
		 
		 
		








 
  
 



 
                        
                        










