I am new to programming, taking my first C++ class. I have an assignment and trying to write a C++ code for creating a linked list of Students with operation selections "INSERT, UPDATE, DELETE, SHOW, WRITE". I thought I finished writing the code, because when I'm done I had no errors. However, when I tried to run, "Build Failed" and got errors seen on the image. This is the first time I see this type of error. I will be more than happy if someone help me to figure out why is this happening, and how to solve it. Thank you very much.
My code is following;
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
struct person {
int id;
char name [20];
float grade;
struct person *next ;
}Student;
typedef struct person *StudentPtr;
StudentPtr slist = NULL;
int ItemFound = FALSE;
int ItemExists = FALSE;
void GetStudent (StudentPtr *TemPtr)
{
*TemPtr = (StudentPtr)malloc(sizeof(person));
}
void FindStudent (StudentPtr *PredPtr, StudentPtr *LocPtr, int id)
{
*PredPtr = NULL;
*LocPtr = slist;
ItemFound = FALSE;
ItemExists = FALSE;
while(ItemFound == FALSE && (*LocPtr!=NULL))
{
if((*LocPtr)->id < id)
{
*PredPtr = *LocPtr;
*LocPtr = ((*LocPtr)->next);
}
else
{
ItemFound = TRUE;
if(((*PredPtr)->next)->id == id)
ItemExists = TRUE;
}
}
}
void AddStudent(int id, char name)
{
StudentPtr Something, PredPtr, TemPtr;
FindStudent(&PredPtr, &Something, id);
GetStudent(&TemPtr);
TemPtr->id = id;
TemPtr->grade = 0.0;
strcat(TemPtr->name, &name);
if(ItemExists == TRUE)
printf("Student is already in the list.");
else
{
if(PredPtr == NULL)
{
TemPtr->next = slist;
slist = TemPtr;
printf("[%d, %s] Adding operation is SUCCESSFUL to the linked list. Student order: ", id, &name);
}
else
TemPtr->next = PredPtr->next;
PredPtr->next = TemPtr;
printf("[%d, %s] Adding operation is SUCCESSFUL to the linked list. Student order: ", id, &name);
}
}
void UpdateStudent(int id, float grade)
{
StudentPtr Something, PredPtr;
FindStudent(&PredPtr, &Something, id);
if(ItemExists == FALSE)
printf("[%f] Student does not found! Grade is not changed.]", grade);
else
(PredPtr->next)->grade = grade;
}
void DeleteStudent(int id)
{
StudentPtr LocPtr, PredPtr;
FindStudent(&PredPtr, &LocPtr, id);
if(ItemExists == FALSE)
printf("[%d] Student does not found! Delete operation is not completed.", id);
else
{ if(PredPtr == NULL)
{ slist = LocPtr->next;
free(LocPtr);
printf("[%d] Delete operation is SUCCESSFUL.", id);
}
else
{
PredPtr->next = LocPtr->next;
free(LocPtr);
printf("[%d] Delete operation is SUCCESSFUL.", id);
}
}
}
int main()
{
int ENDED=FALSE;
while(ENDED==FALSE)
{
printf("Welcome to Student Registration Program!\n\n");
printf("[1] Insert, [2] Change, [3] Remove, [4] Show, [5] Write, [9] to exit\n\n");
int selection;
scanf("%d", &selection);
printf("\nSelect: %d\n\n", selection);
if(selection==1 || selection==2 || selection==3 || selection==4 || selection==5 || selection==9)
{
int id;
switch(selection)
{
case 1:
{ char name[40];
char surname[40];
printf("\nPlease input id, name, surname: ");
scanf("%d %s %s", &id, name, surname);
strcat(name, " ");
strcat(name, surname);
void AddStudent(int, char[40]);
AddStudent(id, name);
break;
}
case 2:
{ float grade;
printf("\nPlease input id, grade: ");
scanf("%d %f", &id, &grade);
UpdateStudent(id, grade);
break;
}
case 3:
{ printf("\nPlease input id: ");
scanf("%d", &id);
DeleteStudent(id);
break;
}
case 4:
{ StudentPtr LocPtr = slist;
printf("\n Id Name Grade");
printf("\n---------- -------------- -----");
while(LocPtr != NULL)
{
printf("\n%10d %16s %7.2f", LocPtr->id, LocPtr->name, LocPtr->grade);
LocPtr = LocPtr->next;
}
printf("\nPlease press a button to continue...");
char button;
scanf("%c", &button);
break;
}
case 5:
{ FILE *fout = fopen("Students.txt","w");
StudentPtr temp;
temp = slist;
fprintf(fout, "\n Id Name Grade");
fprintf(fout, "\n---------- -------------- -----");
while(temp != NULL)
{
printf("\n%10d %16s %7.2f", temp->id, temp->name, temp->grade);
temp = temp->next;
}fclose(fout);
printf("\nAll records have been written to the file.");
printf("\nPlease press a button to continue...");
}
case 9:
{ printf("Thanks for using this program. See you later.");
ENDED = TRUE;
}
}
}
else
printf("Please enter a valid selection.");
}
}