What i am trying to do is to create a simple databaseCode:#include <stdio.h> #include <string.h> int keuze1; int keuze2; int keuze3; char pad[200]; char naam[50]; char padnieuw[200]; char naamnieuw[50]; FILE *fp; int regelteller; struct b { char naamvader[20]; char naammoeder[20]; }; struct a { char voornaam[5]; struct b; int leeftijd; float jaarsalaris; }; int werkinbestand (void) { a a; b b; printf("\n\n\n\t[1] Add record to existing file."); printf("\n\t[2] Change recording in existing file."); printf("\n\t[3] Delete a record from an existing file."); printf("\n\t[4] Show existing recorsd for a file."); printf("\n\t[5] Create a new file"); printf("\n\t[6] Close current file and open a new one"); printf("\n\t[7] End program"); printf("\n\n\tGive your choice: "); scanf("%d",& keuze2); switch(keuze2) { case 1: fp = fopen(pad, "a+"); if (fp == NULL) printf("\n\tKan bestand niet openen."); else { printf("First:\n"); scanf("%s", a.voornaam); printf("\nAnother string\n"); scanf("%s", b.naamvader); printf("\nstring:\n"); scanf("%s", b.naammoeder); printf("\nGive age:\n"); scanf("%d", a.leeftijd); printf("\nfloat:\n"); scanf("%f", a.jaarsalaris); fprintf(fp, "\n%s 1| %s 2| %s 3| %d 4| %f", a.voornaam, b.naamvader, b.naammoeder, a.leeftijd, a.jaarsalaris); fclose(fp); } break; case 2: printf("case 2"); break; case 3: printf("case 3"); break; case 4: printf("case 4"); break; case 5: printf("case 5"); break; case 6: printf("case 6"); break; case 7: printf("case 7"); break; } } int werkinnieuwbestand (void) { printf("\n\n\n\t[1] Voeg een record toe."); printf("\n\t[2] Creeer een nieuw bestand."); printf("\n\t[3] Sluit het huidige bestand en selecteer ander (bestaand) bestand."); printf("\n\t[4] Einde programma"); printf("\n\n\tGeef het nummer van uw keuze: "); scanf("%d",& keuze3); switch(keuze3) { case 1: printf("case 1"); break; case 2: printf("case 2"); break; case 3: printf("case 3"); break; case 4: printf("case 4"); break; } } int main (void) { printf("\n\n\n\t[1] Do you want to work in an existing file?"); printf("\n\t[2] Do you want to record a new file?"); printf("\n\n\tNumber of choice: "); scanf("%d",& keuze1); switch(keuze1) { case 1: printf("\n\tGive path of file:\n\n\t"); scanf("%s",& pad); printf("\n\tName of file:\n\n\t"); scanf("%s",& naam); strncat(pad, naam, 250); werkinbestand(); break; case 2: printf("\n\tGeef het pad van het bestand in:\n\n\t"); scanf("%s",& pad); printf("\n\tGeef de naam van het bestand in:\n\n\t"); scanf("%s",& naam); strncat(pad, naam, 250); break; } getchar(); getchar(); }
I want to collect records of 3 strings, one integer and a float (the assigntment says I have to use a struct in a struct so it looks kinda odd right now)
The program crashes after trying to add a record to an existing file
(Option 1 in the menu, path and filename filled in, option 1 in the second menu)
could someone tell me what i am doing wrong?



LinkBack URL
About LinkBacks



