I'm working on a project for a Student Course Registration System. I'm having problems reading data from a text file and storing it in singly linked list, which has to get updated every time a new student is added. The data is stored in an formatted way. The problem is my struct has type char
variables, so it gives me as Assignment Error.
The struct is defined as:
struct Student {
char stdID[10];
char stdName[30];
char stdSemester[5];
Student *next; } *Head, *Tail;
The code that saves the struct is:
// For Saving:
SFile << std->stdID << '\t' << std->stdName << '\t' << std->stdSemester << '\n';
The code to read the text file and display the struct is:
// Display:
system("cls");
cout << "\n\n\n";
cout << "\t\t\t\t LIST OF COURSES" << endl;
cout << "\t\t\t ====================================================\n" << endl;
cout << "\t" << "ID" << "\t" << setw(15) << "Course Name" << "\n\n";
// Initialize:
char ID[10];
char Name[30];
char Sem[5];
ifstream SFile("StudentRecord.txt");
Student *Temp = NULL;
while(!SFile.eof()) {
// Get:
SFile.getline(ID, 10, '\t');
SFile.getline(Name, 30, '\t');
SFile.getline(Sem, 5, '\t');
Student *Std = new Student; //<======== OUCH! Assignment error here
//node*c=new node;
// Assign:
Std->stdID = *ID;
if (Head == NULL) {
Head = Std;
}
else {
Temp = Head;
{
while ( Temp->next !=NULL ) {
Temp=Temp->next;
}
Temp->next = Std;
}
}
}
SFile.close();
system("pause"); }
P.S: I'm Having Problem at Assign Comment;
Will I have to change data type and make the whole project in string
? I preferred char
because I was able to format the output, and in string
i'm sure it reads line by line, so I wont be able stores values from single line.