Help i have a small problem i cant display the data written to this file in a switch statement (case 2) what am i doing wrong..the file data is being written into the text file but i cant display it
insertCode:#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
FILE *fp; //creates a file pointer
typedef struct date_info
{
int day;
char month[12];
int year;
} DATE;
DATE get_date(void); //fucntion to input date info
int open_file(FILE **fp); //function to open a file
void write_file(DATE ); //writes data to file
void get_file (DATE ); //Gets data within file
int read_file(FILE **fp); //Reads information contained in main file
int menu();
int main()
{
DATE date; //Structure data type and variable declared
int input;
input = menu(); //Menu displayed and choice recived
switch(input)
{
case 1:
system("cls");
printf("\n Enter the date please !! ");
open_file(&fp);
date = get_date();
write_file(date);
printf("\n File Written");
fclose(fp);
break;
case 2:
read_file(&fp);
get_file(date);
printf("\n\n");
printf("\n -----------------------------------------");
printf("\n generated:%d-%s-%d",date.day,date.month,date.year);
printf("\n -----------------------------------------");
break;
case 3:
system("cls");
printf("\nPress [Enter] To exit the program ");
getch();
return 0;
break;
default :
printf("\nError wrong input bye !! ");
break;
}//End of CASE
getch();
}
/*FUNCTION DEFINITIONS */
int menu()
{
int choice;
printf("\n Welcome ");
printf("\n -------------------------------");
printf("\n Press [1] to Enter the date");
printf("\n Press [2] to Display the date");
printf("\n Press [3] to Exit");
printf("\n\n Enter Enter your choice : ");
scanf("%d",&choice);
return choice;
}
DATE get_date(void)
{
DATE a;
printf("\n Enter the day :");
scanf("%d",&a.day);
printf(" Enter the month:");
scanf("%s", a.month);
printf(" Enter the year :");
scanf("%d",&a.year);
return a;
}
int open_file(FILE **fp)
{
*fp = fopen("Test.txt","w");
return 0;
}
int read_file(FILE **fp)
{
*fp = fopen("Test.txt","r");
return 0;
}
void write_file(DATE a )
{
fprintf(fp ," %d %s %d",a.day,a.month,a.year);
}
void get_file (DATE a )
{
fscanf(fp ,"%d %s %d",&a.day,a.month,&a.year);
}