|
| 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 » | |
29-03-2006, 22.07.33 | #31 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
|
29-03-2006, 22.14.34 | #32 |
WT Assistant
Registrato: 19-12-2000
Loc.: Cambiano (Torino)
Messaggi: 591
|
buf è una stringa definita come
char *buf; fai una malloc della dimensione (in char) almeno pari alla dimensione della struttura, e poi serializzi i vari membri della struttura con una sprintf() come ti ho fatto vedere prima, mettendo un %s per i tipi stringa, un %d per i tipi intero, etc, con un separatore a scelta tra i vari campi. In questo modo puoi fare l'operazione inversa di estrazione in fase di lettura con una scanf() avente lo stesso formato. Però, se da qualche parte hai le specifiche del formato del file, usa quelle...
___________________________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Care to say "thank you"? |
29-03-2006, 22.20.54 | #33 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
OK grazie proverò
|
30-03-2006, 15.58.08 | #34 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
Allora due punti mi sono un po' oscuri:
1 - Se ho un buffer di char e scrivo tramite la sprintf su questo buffer in realtà sto scrivendo delle stringhe (anche se ci metto dei numeri) e così non può andare se poi devo andarli a riversare su file. 2 - L'header è definito in questo modo: Codice:
typedef struct{ char name[DBF_NAME_LENGTH+1]; short NumCampi; long NumRecords; short dimHeader; short dimRecord; long timestamp; campi campo[MAX_NUM_FIELDS]; }header; Grazie. |
30-03-2006, 16.46.37 | #35 | ||
WT Assistant
Registrato: 19-12-2000
Loc.: Cambiano (Torino)
Messaggi: 591
|
Quota:
Quota:
però forse ti conviene fare una funzione char *serializeHeader(header h*) {} che fa il tutto... Non dico che sia l'unico metodo né il migliore, ma è forse il più pratico se devi poi leggere il file.
___________________________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Care to say "thank you"? |
||
30-03-2006, 16.51.22 | #36 | ||
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
Quota:
Quota:
|
||
30-03-2006, 16.56.49 | #37 | |
WT Assistant
Registrato: 19-12-2000
Loc.: Cambiano (Torino)
Messaggi: 591
|
Quota:
___________________________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Care to say "thank you"? |
|
30-03-2006, 17.02.19 | #38 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
Secondo le specifiche c'è un NULL che separa ogni campo (che sarebbe h->campo) mentre gli altri campi non sono separati. Infine, alla fine dell'header, ci sono 2 NULL. Come faccio a inserire questi NULL?
|
30-03-2006, 17.25.36 | #39 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
Ecco l'ho scritta. Però mi va in Segmentation Fault il penultimo test:
Codice:
char *serializeHeader(header *h, int NumFields){ int i; char *buffer,*tmp; buffer=(char *)malloc(sizeof(h)*NumFields); tmp=(char *)malloc(sizeof(campi)); for(i=0; i< NumFields; ++i) sprintf(tmp,"%s%d%d%d", h->campo[i].name,h->campo[i].fieldtype,h->campo[i].fieldlen,NULL); sprintf(buffer,"%s%d%d%d%d%d%s%d%d", h->name, h->NumCampi, h->NumRecords, h->dimHeader, h->dimRecord, h->timestamp, tmp, NULL, NULL); free(tmp); return buffer; } |
30-03-2006, 17.29.49 | #40 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
Corretta!!! Però al test della correttezza dell'algoritmo mi dà sempre 0 punti:
Codice:
char *serializeHeader(header *h, int NumFields){ int i; char *buffer,*tmp; buffer=(char *)malloc(sizeof(h)+2); tmp=(char *)malloc(sizeof(campi)*NumFields+NumFields); for(i=0; i< NumFields; ++i) sprintf(tmp,"%s%d%d%d", h->campo[i].name,h->campo[i].fieldtype,h->campo[i].fieldlen,NULL); sprintf(buffer,"%s%d%d%d%d%d%s%d%d", h->name, h->NumCampi, h->NumRecords, h->dimHeader, h->dimRecord, h->timestamp, tmp, NULL, NULL); return buffer; } Codice:
int ret=fwrite(buf,sizeof(buf),1,fp); |
30-03-2006, 17.31.28 | #41 |
WT Assistant
Registrato: 19-12-2000
Loc.: Cambiano (Torino)
Messaggi: 591
|
forse qualcosa del genere?
Codice:
tmp = (char *)malloc(sizeof(campi) * numcampi); for(i=0; i< NumFields; ++i) { sprintf(tmp, "%s%d%d%d", h->campo[i].name, h->campo[i].fieldtype, h->campo[i].fieldlen, NULL); } buffer = (char *)malloc(sizeof(h) * NumFields + strlen(tmp)); sprintf(buffer, "%s%d%d%d%d%d%s%d%d", h->name, h->NumCampi, h->NumRecords, h->dimHeader, h->dimRecord, h->timestamp, tmp, NULL, NULL); free(tmp); return buffer;
___________________________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Care to say "thank you"? |
30-03-2006, 17.41.30 | #42 |
WT Assistant
Registrato: 19-12-2000
Loc.: Cambiano (Torino)
Messaggi: 591
|
prova con strlen(buf) al posto di sizeof(buf)
poi hai invertito il secondo e terzo parametro: int ret = fwrite(buf, sizeof(char), strlen(buf), fp);
___________________________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Care to say "thank you"? |
30-03-2006, 17.54.24 | #43 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
Come metto la free(tmp) mi appare questo:
*** glibc detected *** corrupted double-linked list: 0x08054638 *** Se non la metto tutto ok. Però mi dà sempre 0 come punteggio. Ti posto il test che esegue: (mi manca solo questa cosa e poi ho finito tutto ) Codice:
for(;;) { ret = -1; fp = fopen("ProvaTest.dbf", "r"); len = fread(buftest, sizeof(char), 500, fp); fclose(fp); fp = fopen("Prova.dbf", "r"); len1 = fread(buf, sizeof(char), 500, fp); fclose(fp); if (len1 != len) break; // Confronto la prima parte (prima del timestamp) len = DBF_NAME_LENGTH+1+2+4+2+2; if (memcmp(buf, buftest, len)) break; // Confronto la seconda parte (dopo il timestamp) if (memcmp(buf+len+4, buftest+len+4, len1-len-4)) break; ret = LPC_OK; break; } if (ret == LPC_OK) test[numtest].passed = 1; numtest++; |
30-03-2006, 17.56.16 | #44 |
WT Assistant
Registrato: 19-12-2000
Loc.: Cambiano (Torino)
Messaggi: 591
|
mi mandi i files aggiornati?
___________________________________
There are 10 kinds of people in this world, those who can read binary and those who can't. Care to say "thank you"? |
30-03-2006, 18.01.08 | #45 |
Hero Member
Registrato: 15-10-2000
Messaggi: 588
|
|
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 |
Parole in musica | gemma | Chiacchiere in libertà | 415 | 03-06-2007 04.24.48 |
GENERAL PROTECTION FAULT | Slith | Hardware e Overclock | 8 | 24-06-2005 19.51.57 |
Quiz: Versi di canzoni | tisifone | Chiacchiere in libertà | 55 | 02-07-2004 18.13.03 |
fault in ms-dos extender | marcofitaly | Windows 9x/Me/NT4/2000 | 1 | 27-05-2004 22.45.27 |