|
| HOMEPAGE | INDICE FORUM | REGOLAMENTO | ::. | NEI PREFERITI | .:: | RSS Forum | RSS News | NEWS web | NEWS software | |
| PUBBLICITA' | | | ARTICOLI | WIN XP | VISTA | WIN 7 | REGISTRI | SOFTWARE | MANUALI | RECENSIONI | LINUX | HUMOR | HARDWARE | DOWNLOAD | | | CERCA nel FORUM » | |
10-06-2005, 16.17.58 | #1 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
[C] Gestione file
Codice:
#include <stdio.h> #include <windows.h> #include <string.h> #include <conio.h> #define Errore_(x) {puts(x);getch();ExitProcess(1);} int main(int argc, char *argv[]) { HANDLE bookf; //handle al file contenente le informazioni bookf = CreateFile("pippo.txt", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL); if(bookf == INVALID_HANDLE_VALUE){ bookf = CreateFile("pippo.txt", GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(bookf == INVALID_HANDLE_VALUE) Errore_("Impossibile accedere al file pippo!\ \n\nPremere un tasto per terminare..."); } } BOOL ReadFile( HANDLE hFile, // handle of file to read LPVOID lpBuffer, // pointer to buffer that receives data DWORD nNumberOfBytesToRead, // number of bytes to read LPDWORD lpNumberOfBytesRead, // pointer to number of bytes read LPOVERLAPPED lpOverlapped // pointer to structure for data ); per leggere un carattere alla volta dal file in questione e madarlo in output su video sempre un carattere alla volta? Inoltre non capisco una cosa, non dovrei poter usare "CREATE_NEW|OPEN_EXISTING" invece di usare 2 volte CreateFile() una volta col primo e una volta col secondo in caso di fallimento? Ho provato, ma non funziona |
10-06-2005, 21.02.23 | #2 |
Senior Member
Registrato: 04-07-2004
Loc.: là sui monti con Annette...
Messaggi: 380
|
prova ad usare OPEN_ALWAYS....
per leggere un carattere alla vota setta nNumberOfBytesToRead ad 1 per scrivere un carattere penso che devi usare BOOL WriteConsole( HANDLE hConsoleOutput, // handle to a console screen buffer CONST VOID *lpBuffer, // pointer to buffer to write from DWORD nNumberOfCharsToWrite, // number of characters to write LPDWORD lpNumberOfCharsWritten,// pointer to number of characters written LPVOID lpReserved // reserved );
___________________________________
...sempre allegri bisogna stare il nostro piangere fa male al re... |
11-06-2005, 09.51.42 | #3 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
Non posso usare OPEN_ALWAYS, altrimenti se il file esiste la CreateFile() ne cancella il contenuto.
Poi il file conterrà una cosa del genere: a4c5e3f8g0b3h6... la sequenza di operazioni dovrebbe essere: - leggi il primo carattere (sarà una lettera), mettilo in una variabile e stampalo a video (andrà bene anche printf() per questo) - leggi il secondo carattere (sarà un numero), mettilo in una variabile e stampalo a video - leggi il terzo carattere (di nuovo una lettera), mettilo in una variabile (la stessa della prima) e stampalo a video... - e così via fino alla fine del file. |
11-06-2005, 14.23.03 | #4 |
Senior Member
Registrato: 04-07-2004
Loc.: là sui monti con Annette...
Messaggi: 380
|
con OPEN_ALWAYS se il file esiste viene aperto (il contenuto non viene cancellato) altrimenti viene creato il file
ti riporto quello che c'è scritto sulla win32 programmer's reference OPEN_ALWAYS Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDistribution were CREATE_NEW. cmq ho provato e funziona... poi fai un ciclo finchè non arriva alla fine del file e metti ReadFile(bookf,&buf, 1,&p,NULL) dove bookf è l' handle del file, buf è un variabile char, 1 specifica un carattere alla volta, &p è una variabile LPDWORD che contiene i byte effettivamente letti puoi usare sempre la variabile buf e stamparla a video sempre con printf("%c",buf); mentre se a te serve effettivamente il valore 4 come intero ad una variabile intera assegni i=buf-'0'
___________________________________
...sempre allegri bisogna stare il nostro piangere fa male al re... |
11-06-2005, 15.11.45 | #5 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
Cavolo, avevo letto la specifica di CREATE_ALWAYS
|
11-06-2005, 16.15.27 | #6 |
Made in Japan
Top Poster
Registrato: 04-07-2001
Messaggi: 4.461
|
Perfetto, tutto ok.
Grazie |
11-06-2005, 19.11.33 | #7 |
Senior Member
Registrato: 04-07-2004
Loc.: là sui monti con Annette...
Messaggi: 380
|
___________________________________
...sempre allegri bisogna stare il nostro piangere fa male al re... |
Utenti attualmente attivi che stanno leggendo questa discussione: 1 (0 utenti e 1 ospiti) | |
Strumenti discussione | |
|
|
Discussioni simili | ||||
Discussione | Autore discussione | Forum | Risposte | Ultimo messaggio |
Avvio XP lentissimo | sgarragagarru | Windows 7/Vista/XP/ 2003 | 8 | 20-05-2008 20.01.50 |
Gestione del trasferimento file (copia,taglia) con windows xp | m16shooter1 | Windows 7/Vista/XP/ 2003 | 15 | 23-02-2007 19.59.32 |
[Windows XP] Problemi con il masterizzatore DVD | Qgino | Hardware e Overclock | 13 | 16-10-2005 20.11.45 |
computer da immondizzia | ziopazzo | Windows 9x/Me/NT4/2000 | 3 | 09-05-2004 00.20.30 |
problema con file .doc rovinato in office xp 2003...poi risolto... | cippico | Office suite | 0 | 30-04-2004 09.12.07 |