Trying to display my file, but something goes wrong?
*********************************
//An one-card catalog
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define MAX 1
//function defination
void display(int i);
void enter(void);
void save(void);
void load(void);
struct catalog {
char title[80]; //title
} cat[MAX];
int top = 0; //last location used
//Enter title into database
void enter(void){
int i;
char temp[80];
for(i = top; i < MAX; i++){
printf("Enter title: ");
fgets(cat[i].title, 80, stdin);
}
top = i;
}
//Display catalog entry
void display(int i){
printf("%s\n", cat[i].title);
}
//Save the catalog file
void save(void){
FILE *fp;
if((fp = fopen("catalog.txt", "w"))==NULL){
printf("Cannot open catalog file\n");
exit(1);
}
fwrite(cat , 1 , sizeof(cat) , fp );
fclose(fp);
}
//Load the catalog file
void load(void){
FILE *fp;
if((fp = fopen("catalog.txt", "r"))==NULL){
printf("Catalog file ot on disk\n");
return;
}
fread(cat , 1 , sizeof(cat) , fp );
fclose(fp);
}
void main(void){
printf("\nRead title, the function 1\n");
enter();
printf("\nSave the title on file, function 2\n");
save(); //Save the title on file
printf("\nLoad the title from the filen, function 3\n");
load(); //Load the tile from file
printf("\nDisplay the title on screen, function 4\n");
display(top); //Display the title on screen, function 3
}
**************************************