There are some problems with my reading function.
My reading function is:
int readFileToPic(FILE* f, pic* picture_Reccord, int picNumber){
int count = 0;
f = fopen("Record.dat", "rb");
if (f == NULL){
printf("\n Unable to open file!\n");
}
else{
count= fread(&picture_Reccord, sizeof(picture_Reccord), Maximun_Picture, f);
fclose(f);
}
if (count <=0 && count >= Maximun_Picture)
return -1;
//breaking the programe
//picture_Reccord[count].fileName[0] = '\n';
return count;
}
This is how I call it
case 3:
printf("Read picture records from disk\n");
count= readFileToPic(file, pictureRecord, picNumber);
printf("\n\nRead %d photos\n", count);
//testing
printf("\n%d\n", pictureRecord[0].location);
break;
It prints "Read 4 photos" every time and for grabage in the testing part
This is my saving function in case this is where the problems are
void savePic(FILE* f, pic picture_Record){
f= fopen("Record.dat","wb");
if (f == NULL)
{
printf("\nError! Not able to save!\n");
}
fwrite(&picture_Record, sizeof(picture_Record), 1, f);
fclose(f);
printf("One Pic Saved\n");
}
This is my updated struct thanks to @ Jonathan Leffler
typedef struct picture_Data
{
char fileName[Input_Length_fileName];
char description[Input_Length_description];
char location[Input_Length_fileName];
int peopleCount;
}pic;
Can anybody help me and tell me where the problems are ?
Maximum_Pictureis negative, there's no way on Earthcount <=0 && count >= Maximun_Picturecould possibly be true ever.&picture_Reccordin the first function should bepicture_Reccord, because it's already a pointer.fwrite()and read back withfread().fwrite().