I am writing a code that is a menu driven program that takes the input several files, arranges them into structures, and links those structures.
I'm having some difficulty scanning in to the structure though. I can take it from there, I'm just missing this step.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#define ST_SCHED_FILE "sched.txt"
#define COURSE_FILE ""course.txt"
#define ST_ID_FILE "id.txt"
void add_class(void);
void drop_class(void);
void print_classes(void);
int main(void)
{
FILE *fp_schedule, *fp_course, *fp_id;
int command;
struct student_info
{
int student_id;
char last_name[21];
char first_name[21];
char phone_num[11];
struct class_node *first_node;
};
struct class_node
{
char prefix[7];
int section;
int credit_hours;
struct class_node *next_node;
};
if((fp_schedule = fopen(ST_SCHED_FILE, "r")) == NULL)
{
printf("Schedule file cannot be opened. Press enter to exit.");
getchar();
exit(EXIT_FAILURE);
}
/* else
{
}*/
if((fp_course = fopen(COURSE_FILE, "r")) == NULL)
{
printf("Course file cannot be opened. Press enter to exit.");
getchar();
exit(EXIT_FAILURE);
}
/* else
{
}*/
if((fp_id = fopen(ST_ID_FILE, "r")) == NULL)
{
printf("ID cannot be opened. Press enter to exit.");
getchar();
exit(EXIT_FAILURE);
}
/* else
{
}*/
printf("\t\tRegistry\n\n");
printf("[0] Add a class to a student schedule\n");
printf("[1] Drop a class from a student schedule\n");
printf("[2] List the classes for a given student\n");
printf("[3] Exit\n");
command:
printf("Command: ");
scanf(" %d", &command);
switch(command)
{
case 0:
add_class();
printf("Case 0\n");//just debug to make sure it worked properly
break;
case 1:
drop_class();
printf("Case 1\n");
break;
case 2:
print_classes();
printf("Case 2\n");
break;
case 3:
return 0;
default:
printf("You have entered an invalid entry.\n");
goto command;//yes, the ancient goto used once again
}
printf("All files successfully accessed.\n");
getchar();
return 0;
}
void add_class(void)
{
}
void drop_class(void)
{
}
void print_classes(void)
{
}
For the first file has a list of student numbers and classes associated with it, the course prefix and section.
The course file or second fopen contains the list of classes offered, the section, and credit hours applicable.
The student id file or last fopen contains the student id, last name, first name, and telephone number. Struct class_node is the pointer that I'm going to use for the linked list to link the student information and the classes the person has.
fscanf has not worked for me yet. Also I'm not even sure my structures are correct, but it compiles. Thanks in advance for any help. Any links to examples would be helpful as well.