|
|
|
![]() |
|
Strumenti |
![]() |
#1 |
Senior Member
Iscritto dal: Sep 2008
Messaggi: 1271
|
[ANSI C89] Manipolazione file
Stò lavorando con dei file e ho due domande:
1-Perché la sequenza di fine file è \377 invece di \0 (Uso OSX); 2-Perché mi posiziono, ad esempio, al quarto carattere dall'inizio del file, e poi chiamo rispettivamente fgetc() e fputc(), tra una chiamata e l'altra lo stream punta la fine del file? Mi spiego, con un codice come questo: Codice:
FILE *fp=fopen("file","r+"); fseek(fp, 4L, SEEK_SET); printf("%c\n", (unsigned char) fgetc(fp)); fputc('o', fp); while(!feof(fp)) printf("%c", (unsigned char) fgetc(fp)); FIX'D
__________________
MacBook 6,1|2,26 Ghz C2D|2GB 1067 Mhz DDR3|GeForce 9400M|Mac OSX 10.6.2 Ultima modifica di M4rk191 : 24-01-2010 alle 12:30. |
![]() |
![]() |
![]() |
#2 |
Senior Member
Iscritto dal: Apr 2000
Città: Vicino a Montecatini(Pistoia) Moto:Kawasaki Ninja ZX-9R Scudetti: 29
Messaggi: 53971
|
Il carattere di fine file è EOF, il valore che assume dipende da sistema operativo a sistema operativo.
"w+" Create an empty file for both reading and writing. If a file with the same name already exists its content is erased and the file is treated as a new empty file. |
![]() |
![]() |
![]() |
#3 | |
Senior Member
Iscritto dal: Sep 2008
Messaggi: 1271
|
Quote:
![]() La seconda no, per un errore mio. Nell'esempio ho scritto "w+", mentre avrei dovuto scrivere "r+".
__________________
MacBook 6,1|2,26 Ghz C2D|2GB 1067 Mhz DDR3|GeForce 9400M|Mac OSX 10.6.2 |
|
![]() |
![]() |
![]() |
Strumenti | |
|
|
Tutti gli orari sono GMT +1. Ora sono le: 04:26.