Ultron Δημοσ. 2 Δεκεμβρίου 2011 Μέλος Δημοσ. 2 Δεκεμβρίου 2011 Sorry για το off-topic, αλλά τι κακό είναι αυτό ρε παιδιά με τους κώδικες "ορνιθοσκαλίσματα"; Έχετε τσακωθεί με τα tabs και τα spaces; 8 στους 10 κώδικες που ποστάρονται στο φόρουμ από αρχάριους θέλουν... αποκρυπτογράφηση! Προσωπικά έχω πάψει να ρίχνω καν 2η ματιά σε τέτοιου είδους κώδικες... βασικα δεν ηξερα τι παιζει με το "code" για αυτο εσβησα οτι κενα ειχε > do { printf("Enter UniqueID: "); scanf("%d",&i); while ((fread((char *) &data, sizeof (data), 1, file)) == 1) { // if (i == data.uniqueid) { // system("cls"); // printf("To ID auto uparxei HDH,parakalw epanaplhktrologiste\n"); // system("pause"); // system("cls"); // printf("enter unique id(in the loop):"); // fflush(stdout); // scanf ( "%d",&i); // } // if (i != data.uniqueid)break; } } while (!mygeti(&data.uniqueid)); >int mygeti(int *result) { char buff [ 13 ]; /* signed 32-bit value, extra room for '\n' and '\0' */ return fgets(buff, sizeof buff, stdin) && sscanf(buff, "%d", result) == 1; } >void pelates_write(const char *filename) { FILE *file = fopen(filename, "ab"); /* append to the file in binary mode */ if (file != NULL) { struct pelates data; Ορίστε και η αρχή του (νομιζω ειναι αυτο που ζητησες)
migf1 Δημοσ. 2 Δεκεμβρίου 2011 Δημοσ. 2 Δεκεμβρίου 2011 Φτιάχτο λοιπόν (και βαλέ και τον ορισμό της δομής data) EDIT: Α το έφτιαξες! Ωραία, μισό να το δω Μας δίνεις πολύ λίγες πληροφορίες! Τι είναι το data? Από το cast που κάνεις υποθέτω είναι string (αν ναι, δεν θέλεις & μπροστά από το όνομά του στην fread και το sizeof() είναι λάθος). Επίσης, πως αποθηκεύεις τα data στο αρχείο; Αν είναι strings με fixed size, κάνεις padding στο μέγιστο μέγεθός τους όταν τα αποθηκεύεις στο αρχείο, ώστε να μπορείς να τα διαβάσεις μετά με την fread? Γενικώς, δεν μπορούμε να βοηθήσουμε με αυτόν τον κώδικα έτσι σκέτο. Από edit σε edit πάμε Strings 12+1 χαρακτήρων είναι το data? Δώσε μας τον ορισμό του struct Data.
Ultron Δημοσ. 2 Δεκεμβρίου 2011 Μέλος Δημοσ. 2 Δεκεμβρίου 2011 αυτο που θελω να κανω ειναι το ID Που παιρνει να ειναι unique δηλαδη αν δωσω στην αρχη ID 1 και στην επομενη εισαγωγη δωσω παλι ενα να μην με αφησει! σου στελνω πμ με ολο τον κωδικα,αν θες ofc!
migf1 Δημοσ. 2 Δεκεμβρίου 2011 Δημοσ. 2 Δεκεμβρίου 2011 Δεν θέλω όλο τον κώδικα, θέλω τον ορισμό της δομής που περιέχει μέσα της το id, με το οποίο θες να συγκρίνεις το user-input. Ή μάλλον άστο, θα σου γράψω κώδικα με int id μέσα σε δομή και θα σου τον ποστάρω (απλά είμαι στη δουλειά κι ενδέχεται να αργήσω λιγάκι).
Ultron Δημοσ. 2 Δεκεμβρίου 2011 Μέλος Δημοσ. 2 Δεκεμβρίου 2011 Δεν θέλω όλο τον κώδικα, θέλω τον ορισμό της δομής που περιέχει μέσα της το id, με το οποίο θες να συγκρίνεις το user-input. Ή μάλλον άστο, θα σου γράψω κώδικα με int id μέσα σε δομή και θα σου τον ποστάρω (απλά είμαι στη δουλειά κι ενδέχεται να αργήσω λιγάκι). οκ σου εχω στειλει πμ σε περιπτωση που θες καποια διευκρινηση σε υπερευχαριστω =]]
migf1 Δημοσ. 2 Δεκεμβρίου 2011 Δημοσ. 2 Δεκεμβρίου 2011 οκ σου εχω στειλει πμ σε περιπτωση που θες καποια διευκρινηση σε υπερευχαριστω =]] Οκ το πήρα, θα σου φτιάξω στα γρήγορα κώδικα που θα γράφει και θα διαβάζει... αλλά θα το κάνω σε μονοκόματο πίνακα από δομές (μέχρι πόσους πελάτες πρέπει να διαχειρίζεται το πρόγραμμα; ) EDIT: Άστο, θα τον δεσμεύω δυναμικά τον πίνακα.
Ultron Δημοσ. 2 Δεκεμβρίου 2011 Μέλος Δημοσ. 2 Δεκεμβρίου 2011 Οκ το πήρα, θα σου φτιάξω στα γρήγορα κώδικα που θα γράφει και θα διαβάζει... αλλά θα το κάνω σε μονοκόματο πίνακα από δομές (μέχρι πόσους πελάτες πρέπει να διαχειρίζεται το πρόγραμμα; ) EDIT: Άστο, θα τον δεσμεύω δυναμικά τον πίνακα. Ok!
migf1 Δημοσ. 2 Δεκεμβρίου 2011 Δημοσ. 2 Δεκεμβρίου 2011 Δυστυχώς δεν ευκαίρησα να ασχοληθώ, είμαι ακόμα στη δουλειά. Αλλά φεύγω και θα το κοιτάξω σε καμιά ώρα που θα είμαι σπίτι.
Ultron Δημοσ. 2 Δεκεμβρίου 2011 Μέλος Δημοσ. 2 Δεκεμβρίου 2011 Δυστυχώς δεν ευκαίρησα να ασχοληθώ, είμαι ακόμα στη δουλειά. Αλλά φεύγω και θα το κοιτάξω σε καμιά ώρα που θα είμαι σπίτι. Δεν υπαρχει θεμα φιλε μου!Με την ησυχια σου! Ευχαριστω πολυ και παλι!
παπι Δημοσ. 3 Δεκεμβρίου 2011 Δημοσ. 3 Δεκεμβρίου 2011 Συντακτικα ειναι το ιδιο (και πρακτικα) Καμια σχεση. > char str1[] = "Hello"; // Data segment (uninitialized a.k.a bss) (μπορει να αλλαξει σε runtime) char *str2 = "Hello"; // Data segment (initialized) (ΔΕΝ μπορει να αλλαξει σε runtime) int main(int argc,char**) { char str3[] = "Hello";// Stack segment (μπορει να αλλαξει σε runtime, οταν πεθανει η stack ψοφαει κι αυτο) char *str4 = "Hello";// Data segment (εκει που ειναι και το str2) static char str5[] = "Hello";//Data segment (εκει που ειναι και το str1) return 0; } anyone? :s :/Βαλε στην αρχη του αρχειου ενα int που θα ειναι o "indexer", ετσι οταν βαζεις ενα "record" θα πας στην αρχη του αρχειου, θα διαβασεις τον indexer θα τον αυξησεις, θα τον κανεις append στο αρχειο (στην αρχη) και τελος θα εχεις το unique id σου.
migf1 Δημοσ. 3 Δεκεμβρίου 2011 Δημοσ. 3 Δεκεμβρίου 2011 Δυστυχώς δεν ευκαίρησα να ασχοληθώ, είμαι ακόμα στη δουλειά. Αλλά φεύγω και θα το κοιτάξω σε καμιά ώρα που θα είμαι σπίτι. Πω πω, σε μεγάλο τριπάκι μπήκα τελικά κι όχι τίποτε άλλο, είμαι λιώμα και με έχει πάρει το ξημέρωμα. Μου βγήκε και πολύπλοκο και ούτε ξέρω τι ακριβώς έχω κάνει Τέσπα, η βασική ιδέα είναι πως φορτώνεις μονοκόμματο το αρχείο στην μνήμη όταν ξεκινάει το πρόγραμμα και ότι εργασίες έχεις να κάνεις τις κάνεις στη μνήμη. Άμα αλλάξεις οτιδήποτε, τότε τα data γίνονται "touched" και σου εμφανίζεται μόνιμα μήνυμα πως "εκκρεμεί αποθήκευση", μέχρι να αποθηκεύσεις από την σχετική επιλογή του μενού. Επίσης βγαίνοντας από το πρόγραμμα αποθηκεύονται αυτόματα τα data σου (αν είναι 'touched"). Και στις 2 περιπτώσεις, η αποθήκευση γίνεται και πάλι μονοκόμματα. Το buffer της μνήμης είναι το pelates που αρχικά γίνεται calloc() σε 10.000 (μηδενισμένες) εγγραφές. Με τα 3 πεδία που του έχω πιάνει κάτι λιγότερο από μισό Mb... με όλα τα πεδία που είχες εσύ έπιανε γύρω στα 800 Kb. Ως unique Id μπορεί να χρησιμοποιηθεί οποιοσδήποτε θετικός, ΜΗ ΜΗΔΕΝΙΚΟΣ, ακέραιος στο εύρος των unsigned int. Δεν επιτρέπω το 0 γιατί το χρησιμοποιώ ως χαρακτηρισμό των κενών εγγραφών του buffer. Έχω βάλει κι έναν στοιχειώδη error-checking μηχανισμό, που τον ξεκίνησα μόνο για τη διαχείριση τουαρχείου, αλλά τελικά ελέγχει και για μερικές ακόμα περιπτώσεις.. μη σε απασχολεί αν δεν πολυ-καταλαβαίνεις των κώδικά του... έτσι κι αλλιώς υποθέτω είναι overkill για την περίπτωσή σου. Το διάβασμα και το φόρτωμα του αρχείου το κάνωμε τις fread / fwrite οι οποίες όμως έχουν το πρόβλημα ότι το αρχείο μπορεί να διαβαστεί μόνο σε όσα μηχανήματα έχουν την ίδια αρχιτεκτονική με το μηχάνημα/πλατφόρμα στο οποίο πρωτο-δημιουργήθηκε το αρχείο). Τέτοιες ώρες όμως τέτοια λόγια, το έκανα έτσι γιατί είναι πιο εύκολο στον κώδικα... μπορείς να χρησιμοποιήσεις τις fscanf / fprintf αν θέλεις (αν και το σωστό είναι να γίνεται serialization, αλλά είναι ψιλά γράμματα τώρα αυτά) Σχόλια έχω βάλει πολύ λίγα, γιατί δεν βλέπω τη μύτη μου από τη νύστα και την κούραση Παραθέτω τον κώδικα σε spoiler γιατί είναι 500 γραμμές... > #include <stdio.h> #include <stdlib.h> #include <string.h> #define INPUTSIZE (255+1) #define STRSIZE (19+1) #define FILENAME "pelates.dat" #define NCUSTOMERS 10000 #define PRTLIST_BREAK 22 enum ErrorID { ERR_FATAL = -1, ERR_NOERROR = 0, ERR_INTERNAL, ERR_NOMEM, ERR_FILE_UNKNOWN, ERR_FREAD_NOOPEN, ERR_FWRITE_NOOPEN, ERR_FILE_FEOF, ERR_FILE_FERROR, }; enum MenuOption { MNSEL_EXIT = '0', MNSEL_NEW_CUSTOMER, MNSEL_FIND_CUSTOMER, MNSEL_SHOW_ALL, MNSEL_SAVE_ALL, /* not really a menu-selection, just their total count */ MNSEL_ALL }; #define VALID_MNSEL(c) ( (c) >= MNSEL_EXIT && (c) < MNSEL_ALL ) typedef enum { FALSE=0, TRUE } Bool; typedef struct Pelates { unsigned int id; /* must be unique, non-0, positive */ char fname[ STRSIZE ]; char lname[ STRSIZE ]; } Pelates; /* crossplatform alternative to windows' system("pause") */ #define pressENTER() \ do{ \ char myInBUFer[255]={'\0'}; \ printf("\nπατηστε ENTER..."); \ fgets(myInBUFer, 255, stdin); \ }while(0) /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID read_data( Pelates *pelates ) { FILE *fp = NULL; enum ErrorID reterr = ERR_NOERROR; if ( !pelates ) return ERR_INTERNAL; fp = fopen( FILENAME, "r" ); /* file does not exist */ if ( !fp ) return ERR_FREAD_NOOPEN; if ( fread( pelates, sizeof( Pelates ), NCUSTOMERS, fp ) != NCUSTOMERS ) { /* data were NOT read successfully */ if ( feof(fp) ) reterr = ERR_FILE_FEOF; else if ( ferror(fp) ) reterr = ERR_FILE_FERROR; else reterr = ERR_FILE_UNKNOWN; } if ( fp ) fclose(fp); return reterr; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID save_data( const Pelates *pelates ) { FILE *fp = NULL; enum ErrorID reterr = ERR_NOERROR; if ( !pelates ) return ERR_INTERNAL; fp = fopen( FILENAME, "w" ); if ( !fp ) /* cannot open file */ return ERR_FWRITE_NOOPEN; if ( fwrite( pelates, sizeof( Pelates ), NCUSTOMERS, fp ) != NCUSTOMERS ) { /* data NOT written successfully */ if ( feof(fp) ) reterr = ERR_FILE_FEOF; else if ( ferror(fp) ) reterr = ERR_FILE_FERROR; else reterr = ERR_FILE_UNKNOWN; } if ( fp ) fclose(fp); return reterr; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID manage_error( enum ErrorID err ) { switch ( err ) { case ERR_FREAD_NOOPEN: /* file NOT read */ break; case ERR_FWRITE_NOOPEN: fputs("σφάλμα εγγραφής αρχείου: χρησιμοποιείται ήδη; δεν υπάρχει χώρος;", stderr); break; case ERR_FILE_FEOF: fputs("*** μοιραίο σφάλμα: πρόωρο τελείωμα αρχείου, τερματισμός προγράμματος", stderr); goto ret_fatal; case ERR_FILE_FERROR: fputs("*** σφάλμα αρχείου: ημιτελής ανάγνωση/εγγραφή", stderr); break; case ERR_NOMEM: fputs("*** μοιραίο σφάλμα: ανεπαρκής μνήμη, τερματισμός προγράμματος", stderr); goto ret_fatal; case ERR_INTERNAL: fputs("*** μοιραίο εσωτερικό σφάλμα: τερματισμός προγράμματος", stderr); goto ret_fatal; case ERR_FILE_UNKNOWN: fputs("*** άγνωστο σφάλμα αρχείου: κρατήστε αντίγραφο και τερματίστε το πρόγραμμα", stderr); goto ret_fatal; case ERR_FATAL: fputs("*** μοιραίο σφάλμα: τερματισμός προγράμματος", stderr); goto ret_fatal; default: break; } return err; ret_fatal: return ERR_FATAL; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int get_firstempty( const Pelates *pelates ) { register int i = 0; if ( !pelates ) return -1; for (i=0; i < NCUSTOMERS && pelates[i].id != 0; i++) ; return i; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool show_stats( const Pelates *pelates, const int firstempty ) { if ( !pelates || firstempty < 0 || firstempty > NCUSTOMERS-1 ) return FALSE; puts("\t----------------------------------"); printf( "\tΚαταχωρημένα: %d | Διαθέσιμα: %d\n", firstempty, NCUSTOMERS-firstempty ); printf( "\t(δεσμευμένη μνήμη: %.2f Kbytes)\n", NCUSTOMERS * (double) sizeof(Pelates) / 1024 ); puts("\t----------------------------------"); return TRUE; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool isunique_id( const Pelates *pelates, const unsigned id ) { register int i; if ( !pelates || id < 1 ) return FALSE; for (i=0; i < NCUSTOMERS; i++) if ( pelates[i].id == id ) return FALSE; return TRUE; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int insert( Pelates *pelates, int *firstempty, Bool *istouched ) { int tempint = 0; char input[ INPUTSIZE ] = {'\0'}; if ( !pelates || !firstempty || *firstempty < 0 || *firstempty > NCUSTOMERS-1 ) return -1; if ( *firstempty == NCUSTOMERS-1 ) { printf("\n*** Δεν υπάρχει χώρος για άλλες καταχωρήσεις! ***"); return *firstempty; } printf("\n\tΕΙΣΑΓΩΓΗ ΠΕΛΑΤΗ #%d\n\n", *firstempty+1 ); do { printf("\tΜοναδικό θετικό ID \t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); } while ( !isunique_id( pelates, tempint ) ); pelates[ *firstempty ].id = tempint; printf("\tΌνομα\t\t\t: "); fgets( input, INPUTSIZE, stdin); input[ strlen(input)-1 ] = '\0'; strncpy( pelates[ *firstempty ].fname, input, STRSIZE-1 ); printf("\tΕπώνυμο\t\t\t: "); fgets( input, INPUTSIZE, stdin); input[ strlen(input)-1 ] = '\0'; strncpy( pelates[ *firstempty ].lname, input, STRSIZE-1 ); puts("\n\t*** ο πελάτης εισήχθη επιτυχώς ***\n"); *istouched = TRUE; return ++(*firstempty); } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool print_single_atpos( const Pelates *pelates, const int pos ) { if ( !pelates || pos < 0 || pos > NCUSTOMERS-1 || pelates[ pos ].id == 0 ) return FALSE; printf("\n\tΠΕΛΑΤΗΣ #%d\n\n", pos); printf("\tΜοναδικό θετικό ID \t: %d\n", pelates[ pos ].id ); printf("\tΌνομα\t\t\t: %s\n", pelates[ pos ].fname ); printf("\tΕπώνυμο\t\t\t: %s\n\n", pelates[ pos ].lname ); return TRUE; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int find( Pelates *pelates ) { unsigned int id; int retpos = -1; char input[ INPUTSIZE ] = {'\0'}; register int i = 0; if ( !pelates ) return -1; do { printf("\n\tΜοναδικό θετικό ID \t: "); fgets(input, INPUTSIZE, stdin); id = atoi(input); } while (id < 1 ); for (i=0; pelates[i].id != id && i < NCUSTOMERS && pelates[i].id != 0; i++) ; if ( id == pelates[i].id ) { print_single_atpos( pelates, i ); pressENTER(); retpos = i; } else puts("\n\t*** Δεν βρέθηκε πελάτης με αυτό το Id ***"); putchar('\n'); return retpos; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool print_list( Pelates *pelates ) { register int i = 0; if ( !pelates ) return FALSE; if ( pelates[0].id == 0 ) { puts("\n\n\t*** Δεν υπάρχουν καταχωρήσεις ***\n"); return FALSE; } puts("\n\tΛΙΣΤΑ ΠΕΛΑΤΩΝ"); for (i=0; i < NCUSTOMERS && pelates[i].id != 0; i++) { if ( i % PRTLIST_BREAK == 0 ) { if ( i != 0 ) pressENTER(); printf("\n\t%-5s %-25s %-25s\n", "ID", "Όνομα", "Επώνυμο"); puts("\t---------------------------------------------------"); } printf( "\t%-5d %-25s %-25s\n", pelates[i].id, pelates[i].fname, pelates[i].lname ); } pressENTER(); puts("\n"); return TRUE; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID do_menu_option( const int c, Pelates *pelates, int *firstempty, Bool *istouched ) { enum ErrorID reterr = ERR_NOERROR; if ( !pelates || !firstempty || !istouched ) return FALSE; switch ( c ) { case MNSEL_NEW_CUSTOMER: *firstempty = insert( pelates, firstempty, istouched ); break; case MNSEL_FIND_CUSTOMER: find( pelates ); break; case MNSEL_SHOW_ALL: print_list( pelates ); break; case MNSEL_SAVE_ALL: reterr = save_data( pelates ); if ( reterr == ERR_NOERROR ) *istouched = FALSE; break; case MNSEL_EXIT: if ( *istouched ) { puts("\n\tαποθήκευση εκκρεμών στοιχείων..."); pressENTER(); reterr = save_data( pelates ); } break; default: break; } return reterr; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int get_menu_option( const Bool istouched ) { char input[ INPUTSIZE ] = {'\0'}; putchar('\n'); printf("\t%c. Νέος πελάτης\n", MNSEL_NEW_CUSTOMER); printf("\t%c. Αναζήτηση πελάτη\n", MNSEL_FIND_CUSTOMER); printf("\t%c. Λίστα πελατών\n", MNSEL_SHOW_ALL); printf("\t%c. Αποθήκευση Όλων\n", MNSEL_SAVE_ALL); putchar('\n'); printf("\t%c. Έξοδος\n\n", MNSEL_EXIT); printf("%s", istouched ? "\t*** ΕΚΚΡΕΜΕΙ ΑΠΟΘΗΚΕΥΣΗ ***\n\n" : ""); do { printf("\t> "); fgets(input, INPUTSIZE, stdin); } while ( !VALID_MNSEL( *input ) ); return *input; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID init( Pelates **pelates, int *firstempty ) { enum ErrorID reterr = ERR_NOERROR; /* allocate space for all customers */ *pelates = calloc( NCUSTOMERS, sizeof( Pelates ) ); if ( !*pelates ) return ERR_NOMEM; /* read the data file or create one if not found */ reterr = read_data( *pelates ); if ( reterr == ERR_NOERROR ) puts("\tανάγνωση αρχείου καταχωρήσεων... επιτυχής!\n"); else if ( reterr == ERR_FREAD_NOOPEN ) /* file was NOT read */ { printf("\tδημιουργία νέου αρχειου καταχωρήσεων... "); if ( save_data( *pelates ) != ERR_NOERROR ) { /* cannot create it either */ puts( "απέτυχε!\n"); return ERR_FATAL; } puts( "επιτυχής!\n"); } /* get the first empty slot (for the next insertion) */ *firstempty = get_firstempty( *pelates ); return reterr; } /* --------------------------------------------------------------------------------------- */ int main( void ) { enum MenuOption c; /* menu selection */ int firstempty = 0; /* 1st empty slot in the array */ Bool istouched = FALSE; /* TRUE when data need to be saved */ Pelates *pelates = NULL; /* array of customers */ enum ErrorID err = ERR_NOERROR; /* for our primitive error-checking system */ /* initialization */ err = init( &pelates, &firstempty ); if ( manage_error( err ) == ERR_FATAL ) goto exit_failure; /* the main loop */ do { show_stats( pelates, firstempty ); c = get_menu_option( istouched ); err = do_menu_option( c, pelates, &firstempty, &istouched ); if ( manage_error( err ) == ERR_FATAL ) goto exit_failure; } while ( c != MNSEL_EXIT ); /* cleanup & exit */ if ( pelates ) free( pelates ); exit( EXIT_SUCCESS ); exit_failure: if ( pelates ) free( pelates ); pressENTER(); exit( EXIT_FAILURE ); } Όπως πάντα, υπάρχουν τα υπέρ και τα κατά. Δουλεύοντας απευθείας στη μνήμη και αποθηκεύοντας & φορτώνοντας το αρχείο μονοκόμματα, κερδίζεις σε performance με κόστος όμως τη μνήμη, ενδεχομένως και το αυξημένο ρίσκο να χάσεις κάποια data αν προκύψει πρόβλημα πριν να έχεις σώσει τις αλλαγές που έχεις κάνει στη μνήμη (btw, είναι εύκολο να προσθέσεις ένα auto-save χαρακτηριστικό, κάθε x λεπτά). Πάω για νάνιιιιιιιιιιιιιιιιιιιιιιιιιι
Directx Δημοσ. 3 Δεκεμβρίου 2011 Δημοσ. 3 Δεκεμβρίου 2011 Nice job! (+1) Για την ιστορία, αν έχεις κέφι (ήδη έκανες πολύ δουλειά -μια μίνι ΒΔ) άλλαξε το "const unsigned Id" του isunique_id διότι έτσι η συνθήκη if(.. id < 1) δεν οδηγεί σε return FALSE αρνητικών αριθμών, οπότε η είσοδος πχ του "-1" γίνεται δεκτή ως Id. Επίσης αν ο χρήστης ξεπεράσει το INPUTSIZE (δώσει ένα τεράστιο string ως input) τότε παρουσιάζεται η ανάγκη για καθαρισμό (fflush "hack") του stdin (αυτό σε BC++ compiler).
Ultron Δημοσ. 3 Δεκεμβρίου 2011 Μέλος Δημοσ. 3 Δεκεμβρίου 2011 Σε ευχαριστώ παρα πολύ φιλε παω να λιωσω και εγω τωρα ^^
migf1 Δημοσ. 3 Δεκεμβρίου 2011 Δημοσ. 3 Δεκεμβρίου 2011 @Ultron: τίποτα, καλή συνέχεια! @directx: Thanks! Πιθανότατα υπάρχουν κι άλλες αβλεψίες, με οδοντογλυφίδες στα βλέφαρα τον έγραψα τον κώδικα
Ultron Δημοσ. 4 Δεκεμβρίου 2011 Μέλος Δημοσ. 4 Δεκεμβρίου 2011 Καλησπέρα και παλι! για ακομα μια φορα ευχαριστω τον migf1 και ολους τους αλλους! εβαλα δικο μου πινακα κλπ και δεν μου το τρεχει ομως =[ >#include <stdio.h> #include <stdlib.h> #include <string.h> #define INPUTSIZE (255+1) #define STRSIZE (19+1) #define FILENAME "pelates.dat" #define NCUSTOMERS 10000 #define FILENAME1 "prosopiko.dat" #define NEMPLOYEES 10000 #define PRTLIST_BREAK 22 enum ErrorID { ERR_FATAL = -1, ERR_NOERROR = 0, ERR_INTERNAL, ERR_NOMEM, ERR_FILE_UNKNOWN, ERR_FREAD_NOOPEN, ERR_FWRITE_NOOPEN, ERR_FILE_FEOF, ERR_FILE_FERROR }; enum MenuOption { MNSEL_EXIT = '0', MNSEL_NEW_CUSTOMER, MNSEL_FIND_CUSTOMER, MNSEL_NEW_EMPLOYEE, MNSEL_FIND_EMPLOYEE, MNSEL_SHOW_ALL_CUSTOMER, MNSEL_SAVE_ALL_CUSTOMER, MNSEL_SHOW_ALL_EMPLOYEE, MNSEL_SAVE_ALL_EMPLOYEE, /* not really a menu-selection, just their total count */ MNSEL_ALL }; #define VALID_MNSEL(c) ( (c) >= MNSEL_EXIT && (c) < MNSEL_ALL ) typedef enum { FALSE = 0, TRUE } Bool; typedef struct Pelates { unsigned int id; /* must be unique, non-0, positive */ char fname[ STRSIZE ]; char lname[ STRSIZE ]; char country[sTRSIZE]; int age; int roomcode; int roomprice; } Pelates; typedef struct Prosopiko { unsigned int id; char fname[sTRSIZE]; char lname[sTRSIZE]; int age; int salary; int yearhired; } Prosopiko; /* crossplatform alternative to windows' system("pause") */ #define pressENTER() \ do{ \ char myInBUFer[255]={'\0'}; \ printf("\Patiste ENTER..."); \ fgets(myInBUFer, 255, stdin); \ }while(0) enum ErrorID read_data(Pelates *pelates) { FILE *fp = NULL; enum ErrorID reterr = ERR_NOERROR; if (!pelates) return ERR_INTERNAL; fp = fopen(FILENAME, "r"); /* file does not exist */ if (!fp) return ERR_FREAD_NOOPEN; if (fread(pelates, sizeof ( Pelates), NCUSTOMERS, fp) != NCUSTOMERS) { /* data were NOT read successfully */ if (feof(fp)) { printf("lolo"); reterr = ERR_FILE_FEOF; } else if (ferror(fp)) reterr = ERR_FILE_FERROR; else reterr = ERR_FILE_UNKNOWN; } if (fp) fclose(fp); return reterr; } enum ErrorID save_data(const Pelates *pelates) { FILE *fp = NULL; enum ErrorID reterr = ERR_NOERROR; if (!pelates) return ERR_INTERNAL; fp = fopen(FILENAME, "w"); if (!fp) /* cannot open file */ return ERR_FWRITE_NOOPEN; if (fwrite(pelates, sizeof ( Pelates), NCUSTOMERS, fp) != NCUSTOMERS) { /* data NOT written successfully */ if (feof(fp)) { printf("lol"); reterr = ERR_FILE_FEOF; } else if (ferror(fp)) reterr = ERR_FILE_FERROR; else reterr = ERR_FILE_UNKNOWN; } if (fp) fclose(fp); return reterr; } enum ErrorID read_datap(Prosopiko *prosopiko) { FILE *fp = NULL; enum ErrorID reterr = ERR_NOERROR; if (!prosopiko) return ERR_INTERNAL; fp = fopen(FILENAME1, "r"); /* file does not exist */ if (!fp) return ERR_FREAD_NOOPEN; if (fread(prosopiko, sizeof ( Prosopiko), NEMPLOYEES, fp) != NEMPLOYEES) { /* data were NOT read successfully */ if (feof(fp)) { printf("lala"); reterr = ERR_FILE_FEOF; } else if (ferror(fp)) reterr = ERR_FILE_FERROR; else reterr = ERR_FILE_UNKNOWN; } if (fp) fclose(fp); return reterr; } enum ErrorID save_datap(const Prosopiko *prosopiko) { FILE *fp = NULL; enum ErrorID reterr = ERR_NOERROR; if (!prosopiko) return ERR_INTERNAL; fp = fopen(FILENAME1, "w"); if (!fp) /* cannot open file */ return ERR_FWRITE_NOOPEN; if (fwrite(prosopiko, sizeof ( Prosopiko), NEMPLOYEES, fp) != NEMPLOYEES) { /* data NOT written successfully */ if (feof(fp)) { printf("lala"); reterr = ERR_FILE_FEOF; } else if (ferror(fp)) reterr = ERR_FILE_FERROR; else reterr = ERR_FILE_UNKNOWN; } if (fp) fclose(fp); return reterr; } enum ErrorID manage_error(enum ErrorID err) { switch (err) { case ERR_FREAD_NOOPEN: /* file NOT read */ break; case ERR_FWRITE_NOOPEN: fputs("Sfalma Egraffhs arxeiou.", stderr); break; case ERR_FILE_FEOF: fputs("*** Fatal Error:Kleisimo feof", stderr); goto ret_fatal; case ERR_FILE_FERROR: fputs("*** Sfalam arxeiou: hmitelhs anagnwsh", stderr); break; case ERR_NOMEM: fputs("*** Fatal error:aneparkhs mnhmh,kleisimo programmatos", stderr); goto ret_fatal; case ERR_INTERNAL: fputs("*** Moiraio eswteriko sfalma,kleisimo programmatos", stderr); goto ret_fatal; case ERR_FILE_UNKNOWN: fputs("*** Agnwsto sfalma arxeiou!", stderr); goto ret_fatal; case ERR_FATAL: fputs("*** Moiraio sfalma!termatismos programmatos", stderr); goto ret_fatal; default: break; } return err; ret_fatal: return ERR_FATAL; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int get_firstempty(const Pelates *pelates) { register int i = 0; if (!pelates) return -1; for (i = 0; i < NCUSTOMERS && pelates[i].id != 0; i++) ; return i; } /*pelates*/ int get_firstemptyp(const Prosopiko *prosopiko) { register int i = 0; if (!prosopiko) return -1; for (i = 0; i < NEMPLOYEES && prosopiko[i].id != 0; i++) ; return i; } /*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool show_stats(const Pelates *pelates, const int firstempty) { if (!pelates || firstempty < 0 || firstempty > NCUSTOMERS - 1) return FALSE; puts("\t----------------------------------"); printf("\tKataxwrimena: %d | Diathesima: %d\n", firstempty, NCUSTOMERS - firstempty ); printf("\t(Desmeumenh mnhmh: %.2f Kbytes)\n", NCUSTOMERS * (double) sizeof (Pelates) / 1024 ); puts("\t----------------------------------"); return TRUE; } /*pelates*/ Bool show_statsp(const Prosopiko *prosopiko, const int firstemptyp) { if (!prosopiko || firstemptyp < 0 || firstemptyp > NEMPLOYEES - 1) return FALSE; puts("\t----------------------------------"); printf("\tKataxwrimena: %d | Diathesima: %d: %d\n", firstemptyp, NEMPLOYEES - firstemptyp ); printf("\tDesmeumenh mnhmh: %.2f Kbytes)\n", NEMPLOYEES * (double) sizeof (Prosopiko) / 1024 ); puts("\t----------------------------------"); return TRUE; } /*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool isunique_id(const Pelates *pelates, const unsigned id) { /*pelates*/ register int i; if (!pelates || id < 1) return FALSE; for (i = 0; i < NCUSTOMERS; i++) if (pelates[i].id == id) return FALSE; return TRUE; } /*pelates*/ Bool isunique_idp(const Prosopiko *prosopiko, const unsigned id) { /*prosopiko*/ register int i; if (!prosopiko || id < 1) return FALSE; for (i = 0; i < NEMPLOYEES; i++) if (prosopiko[i].id == id) return FALSE; return TRUE; } /*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int insert(Pelates *pelates, int *firstempty, Bool *istouched) { int tempint = 0; char input[ INPUTSIZE ] = {'\0'}; if (!pelates || !firstempty || *firstempty < 0 || *firstempty > NCUSTOMERS - 1) return -1; if (*firstempty == NCUSTOMERS - 1) { printf("\n*** Den uparxei xwros gia alles kataxwriseis! ***"); return *firstempty; } printf("\n\tEisagwgh Pelath #%d\n\n", *firstempty + 1); do { printf("\tUnique ID \t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); } while (!isunique_id(pelates, tempint)); pelates[ *firstempty ].id = tempint; printf("\tOnoma\t\t\t: "); fgets(input, INPUTSIZE, stdin); input[ strlen(input) - 1 ] = '\0'; strncpy(pelates[ *firstempty ].fname, input, STRSIZE - 1); printf("\tEpwnumo\t\t\t: "); fgets(input, INPUTSIZE, stdin); input[ strlen(input) - 1 ] = '\0'; strncpy(pelates[ *firstempty ].lname, input, STRSIZE - 1); printf("\tXwra\t\t\t: "); fgets(input, INPUTSIZE, stdin); input[ strlen(input) - 1 ] = '\0'; strncpy(pelates[ *firstempty ].country, input, STRSIZE - 1); printf("\tHlikia\t\t\t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); pelates[ *firstempty ].age = tempint; printf("\tArithmos Dwmatiou\t\t\t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); pelates[ *firstempty ].roomcode = tempint; printf("\tRoom's Price\t\t\t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); pelates[ *firstempty ].roomprice = tempint; puts("\n\t*** O Pelaths Kataxwrithike ***\n"); *istouched = TRUE; return ++(*firstempty); } /*pelates*/ int insertp(Prosopiko *prosopiko, int *firstemptyp, Bool *istouchedp) { int tempint = 0; char input[ INPUTSIZE ] = {'\0'}; if (!prosopiko || !firstemptyp || *firstemptyp < 0 || *firstemptyp > NEMPLOYEES - 1) return -1; if (*firstemptyp == NEMPLOYEES - 1) { printf("\n*** Den uparxei xwros gia alles kataxwriseis! ***"); return *firstemptyp; } printf("\n\tEisagwgh Upallhlou #%d\n\n", *firstemptyp + 1); do { printf("\tUnique ID \t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); } while (!isunique_idp(prosopiko, tempint)); prosopiko[ *firstemptyp ].id = tempint; printf("\tOnoma\t\t\t: "); fgets(input, INPUTSIZE, stdin); input[ strlen(input) - 1 ] = '\0'; strncpy(prosopiko[ *firstemptyp ].fname, input, STRSIZE - 1); printf("\tEpwnumo\t\t\t: "); fgets(input, INPUTSIZE, stdin); input[ strlen(input) - 1 ] = '\0'; strncpy(prosopiko[ *firstemptyp ].lname, input, STRSIZE - 1); printf("\tHlikia\t\t\t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); prosopiko[ *firstemptyp ].age = tempint; printf("\tMisthos Upallhlou\t\t\t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); prosopiko[ *firstemptyp ].salary = tempint; printf("\tXronia Proslipshs\t\t\t: "); fgets(input, INPUTSIZE, stdin); tempint = atoi(input); prosopiko[ *firstemptyp ].yearhired = tempint; puts("\n\t*** O Upallhlos Kataxwrithike ***\n"); *istouchedp = TRUE; return ++(*firstemptyp); } /*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool print_single_atpos(const Pelates *pelates, const int pos) { if (!pelates || pos < 0 || pos > NCUSTOMERS - 1 || pelates[ pos ].id == 0) return FALSE; printf("\n\tPelaths #%d\n\n", pos); printf("\tUnique ID \t: %d\n", pelates[ pos ].id); printf("\tOnoma\t\t\t: %s\n", pelates[ pos ].fname); printf("\tEpitheto\t\t\t: %s\n\n", pelates[ pos ].lname); printf("\tXwra\t\t\t: %s\n\n", pelates[ pos ].country); printf("\tHlikia\t\t\t: %d\n\n", pelates[ pos ].age); printf("\tArithmos Dwmatiou\t\t\t: %d\n\n", pelates[ pos ].roomcode); printf("\tRoom's Price\t\t\t: %d\n\n", pelates[ pos ].roomprice); return TRUE; } /*pelates*/ Bool print_single_atposp(const Prosopiko *prosopiko, const int pos) { if (!prosopiko || pos < 0 || pos > NEMPLOYEES - 1 || prosopiko[ pos ].id == 0) return FALSE; printf("\n\tUpallhlos #%d\n\n", pos); printf("\tUnique ID \t: %d\n", prosopiko[ pos ].id); printf("\tOnoma\t\t\t: %s\n", prosopiko[ pos ].fname); printf("\tEpitheto\t\t\t: %s\n\n", prosopiko[ pos ].lname); printf("\tHlikia\t\t\t: %d\n\n", prosopiko[ pos ].age); printf("\tMisthos\t\t\t: %d\n\n", prosopiko[ pos ].salary); printf("\tXronia Proslipshs\t\t\t: %d\n\n", prosopiko[ pos ].yearhired); return TRUE; } /*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int find(Pelates *pelates) { unsigned int id; int retpos = -1; char input[ INPUTSIZE ] = {'\0'}; register int i = 0; if (!pelates) return -1; do { printf("\n\tEisagwgh Unique ID \t: "); fgets(input, INPUTSIZE, stdin); id = atoi(input); } while (id < 1); for (i = 0; pelates[i].id != id && i < NCUSTOMERS && pelates[i].id != 0; i++) ; if (id == pelates[i].id) { print_single_atpos(pelates, i); pressENTER(); retpos = i; } else puts("\n\t*** Den vrethike pelaths me auto to Id ***"); putchar('\n'); return retpos; }/*pelates*/ int findp(Prosopiko *prosopiko) { unsigned int id; int retpos = -1; char input[ INPUTSIZE ] = {'\0'}; register int i = 0; if (!prosopiko) return -1; do { printf("\n\tEisagwgh Unique ID \t: "); fgets(input, INPUTSIZE, stdin); id = atoi(input); } while (id < 1); for (i = 0; prosopiko[i].id != id && i < NEMPLOYEES && prosopiko[i].id != 0; i++) ; if (id == prosopiko[i].id) { print_single_atposp(prosopiko, i); pressENTER(); retpos = i; } else puts("\n\t*** Den vrethike Upallhlos me auto to Id ***"); putchar('\n'); return retpos; }/*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ Bool print_list(Pelates *pelates) { register int i = 0; if (!pelates) return FALSE; if (pelates[0].id == 0) { puts("\n\n\t*** Den uparxoun kataxwriseis ***\n"); return FALSE; } puts("\n\tLista Pelatwn:"); for (i = 0; i < NCUSTOMERS && pelates[i].id != 0; i++) { if (i % PRTLIST_BREAK == 0) { if (i != 0) pressENTER(); printf("\n\t%-5s %-25s %-25s %-25s %-5s %-5s %-5s\n", "ID", "Onoma", "Epwnumo", "Xwra", "Hlikia", "Arithmos Dwmatiou", "Room's Price"); puts("\t---------------------------------------------------------------------------------------------"); } printf("\t%-5s %-25s %-25s %-25s %-5s %-5s %-5s\n", pelates[i].id, pelates[i].fname, pelates[i].lname, pelates[i].country, pelates[i].age, pelates[i].roomcode, pelates[i].roomprice ); } pressENTER(); puts("\n"); return TRUE; }/*pelates*/ Bool print_listp(Prosopiko *prosopiko) { register int i = 0; if (!prosopiko) return FALSE; if (prosopiko[0].id == 0) { puts("\n\n\t*** Den uparxoun kataxwriseis ***\n"); return FALSE; } puts("\n\tLista Upallhlwn:"); for (i = 0; i < NEMPLOYEES && prosopiko[i].id != 0; i++) { if (i % PRTLIST_BREAK == 0) { if (i != 0) pressENTER(); printf("\n\t%-5s %-25s %-25s %-5s %-5s %-5s\n", "ID", "Onoma", "Epwnumo", "Hlikia", "Misthos", "Xronia Proslipshs"); puts("\t---------------------------------------------------------------------------------------------"); } printf("\t%-5s %-25s %-25s %-5s %-5s %-5s\n", prosopiko[i].id, prosopiko[i].fname, prosopiko[i].lname, prosopiko[i].age, prosopiko[i].salary, prosopiko[i].yearhired ); } pressENTER(); puts("\n"); return TRUE; }/*prosopiko*/ /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID do_menu_option(const int c, Pelates *pelates, Prosopiko *prosopiko, int *firstempty, int *firstemptyp, Bool *istouched, Bool *istouchedp) { enum ErrorID reterr = ERR_NOERROR; if (!pelates || !firstempty || !istouched) return FALSE; if (!prosopiko || !firstemptyp || !istouchedp) return FALSE; switch (c) { case MNSEL_NEW_CUSTOMER: *firstempty = insert(pelates, firstempty, istouched); break; case MNSEL_FIND_CUSTOMER: find(pelates); break; case MNSEL_NEW_EMPLOYEE: *firstemptyp = insertp(prosopiko, firstemptyp, istouchedp); break; case MNSEL_FIND_EMPLOYEE: findp(prosopiko); break; case MNSEL_SHOW_ALL_CUSTOMER: print_list(pelates); break; case MNSEL_SAVE_ALL_CUSTOMER: reterr = save_data(pelates); if (reterr == ERR_NOERROR) *istouched = FALSE; break; case MNSEL_SHOW_ALL_EMPLOYEE: print_listp(prosopiko); break; case MNSEL_SAVE_ALL_EMPLOYEE: reterr = save_datap(prosopiko); if (reterr == ERR_NOERROR) *istouchedp = FALSE; break; case MNSEL_EXIT: if (*istouched) { puts("\n\tApothikeush Stoixeiwn..."); pressENTER(); reterr = save_data(pelates); } if (*istouchedp) { puts("\n\tApothikeush Stoixeiwn..."); pressENTER(); reterr = save_datap(prosopiko); } break; default: break; } return reterr; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ int get_menu_option(const Bool istouched, const Bool istouchedp) { char input[ INPUTSIZE ] = {'\0'}; putchar('\n'); printf("\t%c. Neos Pelaths\n", MNSEL_NEW_CUSTOMER); printf("\t%c. Αναζήτηση πελάτη\n", MNSEL_FIND_CUSTOMER); printf("\t%c. Lista Pelatwn\n", MNSEL_SHOW_ALL_CUSTOMER); printf("\t%c. Apothikeush Pelatwn\n", MNSEL_SAVE_ALL_CUSTOMER); printf("\t%c. Neos Upallhlos\n", MNSEL_NEW_EMPLOYEE); printf("\t%c. Αναζήτηση Upallhlou\n", MNSEL_FIND_EMPLOYEE); printf("\t%c. Lista Upallhlwn\n", MNSEL_SHOW_ALL_EMPLOYEE); printf("\t%c. Apothikeush Upallhlwn\n", MNSEL_SAVE_ALL_EMPLOYEE); putchar('\n'); printf("\t%c. Exodos\n\n", MNSEL_EXIT); printf("%s", istouched ? "\t*** Den exei ginei apothikeush pelatwn***\n\n" : ""); printf("%s", istouchedp ? "\t*** Den exei ginei apothikeush pelatwn***\n\n" : ""); do { printf("\t> "); fgets(input, INPUTSIZE, stdin); } while (!VALID_MNSEL(*input)); return *input; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ enum ErrorID init(Pelates **pelates, int *firstempty) { enum ErrorID reterr = ERR_NOERROR; /* allocate space for all customers */ *pelates = calloc(NCUSTOMERS, sizeof ( Pelates)); if (!*pelates) return ERR_NOMEM; /* read the data file or create one if not found */ reterr = read_data(*pelates); if (reterr == ERR_NOERROR) puts("\tAnagnwsh arxeiou Kataxwrisewn twn pelatwn... EPITYXHS!\n"); else if (reterr == ERR_FREAD_NOOPEN) /* file was NOT read */ { printf("\tDhmiourgia neou arxeiou kataxwrisewn... "); if (save_data(*pelates) != ERR_NOERROR) { /* cannot create it either */ puts("Apetuxe!\n"); return ERR_FATAL; } puts("Epityxhs!\n"); } /* get the first empty slot (for the next insertion) */ *firstempty = get_firstempty(*pelates); return reterr; } enum ErrorID initp(Prosopiko **prosopiko, int *firstemptyp) { enum ErrorID reterr = ERR_NOERROR; /* allocate space for all employees */ *prosopiko = calloc(NEMPLOYEES, sizeof ( Prosopiko)); if (!*prosopiko) return ERR_NOMEM; /* read the data file or create one if not found */ reterr = read_datap(*prosopiko); if (reterr == ERR_NOERROR) puts("\tAnagnwsh arxeiou Kataxwrisewn twn upallhlwn... EPITYXHS!\n"); else if (reterr == ERR_FREAD_NOOPEN) /* file was NOT read */ { printf("\tDhmiourgia neou arxeiou kataxwrisewn... "); if (save_datap(*prosopiko) != ERR_NOERROR) { /* cannot create it either */ puts("Apetuxe!\n"); return ERR_FATAL; } puts("Epityxhs!!\n"); } /* get the first empty slot (for the next insertion) */ *firstemptyp = get_firstemptyp(*prosopiko); return reterr; } /* --------------------------------------------------------------------------------------- * * --------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------- */ int main(void) { enum MenuOption c; /* menu selection */ int firstempty = 0; /* 1st empty slot in the array */ int firstemptyp = 0; /* 1st empty slot in the array */ Bool istouched = FALSE; /* TRUE when data need to be saved */ Bool istouchedp = FALSE; Pelates *pelates = NULL; /* array of customers */ Prosopiko *prosopiko = NULL; /* array of employees */ enum ErrorID err = ERR_NOERROR; /* for our primitive error-checking system */ /* initialization */ err = init(&pelates, &firstempty); if (manage_error(err) == ERR_FATAL) goto exit_failure; err = initp(&prosopiko, &firstemptyp); if (manage_error(err) == ERR_FATAL) goto exit_failure; /* the main loop */ do { show_stats(pelates, firstempty); show_statsp(prosopiko, firstemptyp); c = get_menu_option(istouched, istouchedp); err = do_menu_option(c, pelates, prosopiko, &firstempty, &firstemptyp, &istouched, &istouchedp); if (manage_error(err) == ERR_FATAL) goto exit_failure; } while (c != MNSEL_EXIT); /* cleanup & exit */ if (pelates) free(pelates); exit(EXIT_SUCCESS); if (prosopiko) free(prosopiko); exit(EXIT_SUCCESS); exit_failure: if (pelates) free(pelates); if (prosopiko) free(prosopiko); pressENTER(); exit(EXIT_FAILURE); } καποιος που μπορει να βοηθησει??
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα