Yeah, I didn't catch that was your intention. Study this:
Code:
#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(); //function to open a file
void write_file(DATE ); //writes data to file
DATE get_file (DATE );
int read_file(); //Reads information contained in main file
int menu(void);
int main()
{
DATE date ={0," ",0}; //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 fool !! ");
open_file();
date = get_date();
write_file(date);
printf("\n File Written");
fclose(fp);
//return 0;
break;
case 2:
read_file();
date=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(void)
{
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(void)
{
printf("destroying data\n");
fp = fopen("Test.txt","w");
return 0;
}
int read_file(void)
{
fp = fopen("Test.txt","r");
return 0;
}
void write_file(DATE a )
{
fprintf(fp ,"%d %s %d\n",a.day,a.month,a.year);
}
DATE get_file (DATE a)
{
int n;
n=fscanf(fp ,"%d %s %d",&a.day,a.month,&a.year);
printf("n: %d\n",n);
return a;
}