I made this simple function for a program to record some sort of reminder for a user. I'm asking the title of the reminder, little details about it, and the month to when the reminder is due. Supposedly I should be including the day and year but I only included here the month just to test out if my int month
is working. For some reason, scanf("%d",&sc.month)
seems to not work because when I call it in another function, it prints a different number instead. This is my first big project in C and I'm a little excited about it. I'm currently using dosbox since the school requires us to use dosbox but I'm writing my code in sublime. I tried isolating the int cause I thought maybe the " % ^\n]%*c"
syntax is messing up everything, but the problem still happens.
struct schedule{
char title[50],details[100];
int day,month,year;
};
void createSchedule(){
struct schedule sc;
FILE *fp;
fp = fopen("schedule","ab");
if(fp==NULL){
printf("File not found");
getch();
main();
}
printf("Enter title:");scanf(" %[^\n]%*c",&sc.title);
printf("\nEnter details: ");scanf(" %[^\n]%*c",&sc.details);
printf("\nEnter number: ");scanf("%d",&sc.day);
printf("\nSchedule created!");
fwrite(&sc,sizeof(struct schedule),1,fp);
getch();
fclose(fp);
active();
}
void readSchedule(){
struct schedule sc;
FILE *fp;
fp = fopen("schedule","rb");
printf("Schedules:\n\n");
if(fp==NULL){
printf("File not found");
getch();
main();
}
while(fread(&sc,sizeof(struct schedule),1,fp)){
printf("Title: %s\n",&sc.title);
printf("Details: %s\n",&sc.details);
printf("Day: %d",&sc.day);
}
getch();
fclose(fp);
active();
}