15/06/11 5:52
Ascal
Ciao tutti, sto sviluppando un progetto per la gestione di una libreria(con possibilità di cancellazione, ricerca e prestito di un libro) in C.
Nel momento in cui vado a compilare il codice però ottengo un errore fisso di "Build main error". Il codice è il seguente:
Edit
Esattamente la riga in causa è la terzultima( pos= ricTitle(tit)). Spero possiate aiutarmi.
Nel momento in cui vado a compilare il codice però ottengo un errore fisso di "Build main error". Il codice è il seguente:
Edit
#include <stdio.h> #include <stdlib.h> #include <string.h> #define k 500 struct data{ int gg,mm,aaaa; }dataprest; struct biblioteca{ char titolo[15]; char autore[500]; char editore[k]; char prestito; struct biblioteca* next; }libro[k]; struct biblioteca temp; // struttura di appoggio per operazione su file typedef struct biblioteca *bookPtr; typedef struct Node root; int n=0,sel,x,disp=0,sel2,a; char continua,tit[15]; void readfile(void); void inserimento(void); void prestito (char tit[15]); int controllo (char tit[15]); void contenuto(void ); void delTitle(long pos); void cerTitle(void); long ricTitle(char); void cancTitle(void); void viscontenuto(void); FILE *fp; int main() { bookPtr root = NULL; fopen(root, "r"); printf("\n\n#############Biblioteca#################"); do{ printf("\n\nMenu':"); printf("\n\n 1:Inserimento di un nuovo libro."); printf("\n 2:Prestito di un libro."); printf("\n 3:Controllare se un libro e' in prestito."); printf("\n 4:Visualizzare il numero di libri in prestito da un certo "); printf("giorno."); printf("\n 5:Visualizzare il contenuto dell'intera biblioteca."); printf("\n 6:Rimuovere libro da biblioteca."); printf("\n 7:Exit.\n"); scanf("%d",&sel); switch(sel) { case 1: inserimento(); break; case 2: printf("\n\nInserire titolo del libro da prestare\n"); fflush(stdin); gets(tit); prestito(tit); break; case 3: printf("\n\nInserire titolo del libro da controllare\n"); fflush(stdin); gets(tit); a=controllo(tit); switch(a) { case 0: printf("\n\nLibro in prestito..."); scanf("%c",&continua); break; case 1: printf("\n\nLibro non in prestito..."); scanf("%c",&continua); break; } break; case 4: break; case 5: contenuto(); break; case 6: cancTitle(); break; case 7: break; } }while(sel!=7); printf("\n\n"); system("PAUSE"); return 0; } void readfile(void) { FILE *stream, *fopen(); int numBooks, anno; stream = fopen("books.txt", "r"); stream = numBooks; char tit, aut, edit; if((stream = fopen("books.txt", "r"))== NULL) { printf("\n\nIl file books.txt non può essere aperto.\n"); exit(-1); } int count; for (count = 0; count< numBooks; count++) { fflush(stream); fgets(tit, '\n', stream); fgets(aut, '\n', stream); fgets(edit, '\n', stream); struct biblioteca *item = malloc(sizeof(struct biblioteca)); } fclose(stream); } void cancTitle(void) { char pausa; char tit[15]; long pos; printf("\n\nInserire titolo del libro da rimuovere:..."); gets(tit); // pos = ricTitle(tit); /* if(pos == -1) { printf("\n\nTitolo non presente"); return; }*/ /* fflush(stream); fgets(tit, '\n', stream); bookPtr p = locateNode(root, tit); if( p== NULL) printf("\n\nCancellazione non può essere effettuato"); else if(root == p); next *p; root = p; else { bookPtr q = root; while (q->next != p) q = q->next; q->next = p->next; } delete p;*/ //} void contenuto(); printf("\nConfermare cancellazione? (S/N) "); scanf("%c", &pausa); if(pausa == 'S' || pausa == 's') { delTitle(pos); return; } } void delTitle(long pos) { gets(temp.titolo); strcpy(temp.titolo, ""); gets(temp.autore); strcpy(temp.editore, ""); gets(temp.editore); strcpy(temp.autore, ""); fp= fopen("books.txt", "r+"); fseek(fp, pos, 0); fwrite(&temp, sizeof(struct biblioteca), 1, fp); fclose(fp); } void cercTitle(void) { char pausa; char tit; long pos; printf("\n\t\tRICERCA TITOLO."); printf("\n\t\t-------\n\n"); gets(tit); //pos = ricTitle(tit); } long ricTitle(char tit) { int n; long pos = 0L; fp = fopen("books.txt", "r"); for(;;) { n = fread(&temp, sizeof(struct biblioteca), 1, fp); if( n== 0){ fclose(fp); pos = -1; return (pos); } else if(strcmp(tit, temp.titolo) == 0) { pos = ftell(fp); fclose(fp); return(pos-sizeof(struct biblioteca)); } } } void inserimento(void) { n++; printf("\n\nInserire i dati relativi al libro N. %d",n); printf("\n\nTitolo: "); fflush(stdin); gets(libro[n].titolo); libro[n].prestito='f'; printf("\n\nAutore: "); gets(libro[n].autore); printf("\n\nEditore: "); gets(libro[n].editore); printf("\n\nDati in memoria..."); scanf("%c",&continua); } void prestito(char tit[15]) { disp=0; for(x=1;x<=n;x++) { if(strcmp(libro[x].titolo,tit)==0) { disp=1; if(libro[x].prestito=='f') { printf("\n\nVuoi continuare con il prestito di questo libro?"); printf("\n 1: Si.\n 2: No.\n"); scanf("%d",&sel2); switch(sel2) { case 1: libro[x].prestito='v'; printf("\nPrestito effettuato..."); scanf("%c",&continua); case 2: break; } } else { printf("\nSpiacenti libro gia' in prestito..."); scanf("%c",&continua); } } } if (disp==0) { printf("\n\nSpiacenti questo libro non e' presente in "); printf("questa biblioteca..."); scanf("%c",&continua); } } int controllo(char tit[15]) { for(x=1;x<=n;x++) { if(strcmp(libro[x].titolo,tit)==0) { if(libro[x].prestito=='v') a=0; else a=1; } } return a; } void contenuto(void) { printf("---------------------------------------------------------------"); printf("\n CONTENUTO BIBLIOTECA\n"); printf("---------------------------------------------------------------"); printf("\nN:libro non disponibile S: libro disponibile\n"); printf("---------------------------------------------------------------"); printf("\n|Prestito|\tTitolo libro|\tAutore|\tEditore|\tDataPubblicazione|\n"); printf("---------------------------------------------------------------"); for(x=1;x<=n;x++) { printf("\n| %c |",libro[x].prestito); printf("%s|",temp.titolo); printf("%s|", temp.autore); printf("%s|", temp.editore); printf("\n\n---------------------------------------------------------------"); } void viscontenuto(void) { /* int n; char pausa; fp = fopen("books.txt", "r"); do { n = fread(&temp, sizeof(struct biblioteca), 1, fp); if( n== 0) fclose(fp); else { contenuto(); scanf("%c", &pausa); }*/ } while(n!= 0); }
Esattamente la riga in causa è la terzultima( pos= ricTitle(tit)). Spero possiate aiutarmi.
Ultima modifica effettuata da Ascal 15/06/11 20:23
aaa