I really need the help. This is what i'm working on. The file name is "movie.dat" and currently i was able to save data into the file in this order:
[movie_code] [movie_dur] [movie_title] [movie_rating] [movie_dir] [movie_genre] [movie_status]
[12345] [120] [Movie] [PG13] [Director] [Comedy] [Active]
I want to search for the "movie_code" and change the [movie_status] from Active to Inactive.
So lets say for example i have a movie code 12345 saved in my movie file. I want to change the value from "Active" to "Inactive"for argument sake.
This is the code i was trying to do it with:
Code:
FILE *movie_fp;
movie_fp = fopen("movie.dat", "r+b");
int m_code;
MOVIE movie_data;
printf("*** Welcome to the movie updater! ***\n\n\n");
if(movie_fp != NULL){
printf("Please enter the code of the movie you wish to update: ");
scanf("%d", &m_code);
fseek(movie_fp, sizeof(movie_data) * (m_code - 1 ), SEEK_SET);
fread(&movie_data, sizeof(movie_data), 1, movie_fp);
if(movie_data.movie_code != 0){
movie_data.movie_code = "Inactive";
}
else {
printf("Record not found");
}
}
else{
printf("Something went wrong, file was not found!");
}
fclose(movie_fp);