|
|||||||
|
|
|
![]() |
|
|
Strumenti |
|
|
#1 |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
[C] Ciclo for+Salvataggio: indice nome.
Salve a tutti avrei un piccolo problema da risolvere e non so quale strada percorrere. Il programma che ho scritto genera dei file che salvo con un nome prefissato.Adesso dovrei fare un ciclo for che mi cambi dei parametri e che automaticamente mi salvi i dati in diversi file con un nome diverso per ogni ciclo. Provo a buttare giù due righe per spiegarmi meglio:
vorrei questo risultato Codice:
#define filename "file000.dat"
....
....
for(i=1;i<124;i++)
{
...
...
salva();
}
file001.dat file002.dat .... file123.dat In questo momento non so che cosa fare, non so qual'è la soluzione più veloce e più snella per fare questo. Grazie per ogni consiglio. 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 | |
|
Member
Iscritto dal: Feb 2006
Messaggi: 134
|
Quote:
|
|
|
|
|
|
|
#3 |
|
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Componi il nome del file con sprintf.
Ad esempio: Codice:
char filename[13];
int i;
for(i = 0; i < 1000; i++)
{
sprintf(filename, "file%03d.dat", i);
puts(filename);
}
|
|
|
|
|
|
#4 | ||
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
Quote:
Codice:
/tmp/cck6iP2d.o: In function `main': prova.c:(.text+0x74): undefined reference to `itoa' collect2: ld returned 1 exit status Grazie mille. PS leggendo meglio in http://www.cplusplus.com/reference/c...dlib/itoa.html c'era scritto Quote:
__________________
"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...." |
||
|
|
|
|
|
#5 | |
|
Senior Member
Iscritto dal: Dec 2004
Messaggi: 783
|
Quote:
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...." |
|
|
|
|
|
| Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 23:50.




















