segmentation fault - C char array to binary file -


    int felvetel() {     file *ptr_myfile;     struct stadion* my_record;      my_record = malloc(sizeof(struct stadion) * 1);     ptr_myfile=fopen("test.bin","wb");     if (!ptr_myfile)     {         printf("nem lehet megnyitni fajlt!");         return 1;     }     printf("varos: ");     scanf("%s", my_record[0].varos);     printf("csapat: ");     scanf("%s", my_record[0].csapat);     printf("nezoszam: ");     scanf("%i", my_record[0].nezoszam);     printf("koltseg: ");     scanf("%i", my_record[0].koltseg);     printf("atadas eve: ");     scanf("%i", my_record[0].ev);     printf("atadas honapa: ");     scanf("%i", my_record[0].honap);     printf("atadas napja: ");     scanf("%i", my_record[0].nap);     fwrite(my_record, sizeof(struct stadion), 1, ptr_myfile);     fclose(ptr_myfile);     return 0; } 

it isn't working. when want add int in 3. line got "segmentation fault", dont't know why.

and please check, good?

    int listazas() {     file *ptr_myfile;     struct stadion my_record;      ptr_myfile=fopen("test.bin","rb");     if (!ptr_myfile)     {         printf("nem lehet megnyitni fajlt!");         return 1;     }     while (!(feof(ptr_myfile)))     {         fread(&my_record,sizeof(struct stadion),1,ptr_myfile);         printf("%s\t",my_record.varos);         printf("%s\t",my_record.csapat);         printf("%i\t",my_record.nezoszam);         printf("%i\t",my_record.koltseg);         printf("%i\t",my_record.ev);         printf("%i\t",my_record.honap);         printf("%i\t",my_record.nap);     }     fclose(ptr_myfile);     return 0; } 

i hope working well, couldn't try, becaues don't have in binary file.

why add struct binary file 2 times?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -