#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct NodeT_
{
char name[30], lastName[20];
char year[10];
char id[30];
int randomID;
float average;
char email[30];
char ppsn[10];
struct NodeT_* NEXT;
}node;
void addElementAttheEnd(node* top, char studentID[]);
void addElementAttheStart(node** top, char studentID[]);
void display(node* top);
void displayToFile(node* top);
int checkPpsn(node* top);
int search(node* top, char searchID[]);
int location(node* top, char searchID[]);
int length(node* top);
void deleteAtEnd(node* top);
void deleteAtStart(node** top);
void deleteintheMiddle(node* top, char searchID[]);
void deletedAtLocation(node* top, int loc);
void updateNodeValues(node* top, char ID[]);
int main()
{
node* HEAD = NULL;
node* temp;
node* temp2;
int option;
int searchNum;
int result;
int foundLocation;
char searchTerm[20];
FILE* inp;
node fileValue;
inp = fopen("links.txt", "r");
if (inp == NULL)
printf("Sorry the file could not be opened\n");
else
{
while (!feof(inp))
{
result = fscanf(inp, "%s %s %s %s %s", fileValue.ppsn, fileValue.name, fileValue.lastName, &fileValue.year, fileValue.email);
if (result == 5)
{
printf("%s %s %s %s %s\n", fileValue.ppsn, fileValue.name, fileValue.lastName, fileValue.year, fileValue.email);
}
}
fclose(inp);
}
printf("1) Add customer(Note: PPS Number must be unique).\n");
printf("2) Display all customer details to screen\n");
printf("3) Display Customer Details\n");
printf("4) Update a Customer Details\n");
printf("5) Delete Customer\n");
printf("6) Generate statistics(a – e) based on the user selecting a booking type\n");
printf("7) Print all customer details into a report file.\n");
printf("8) List all the customers in order of year born :\n");
scanf("%d", &option);
while (option != -1)
{
if (option == 1)
{
if (HEAD == NULL)
addElementAttheStart(&HEAD, searchTerm);
else
{
result = location(HEAD, searchTerm);
if (result == -1)
addElementAttheEnd(HEAD, searchTerm);
else
printf("Sorry this student already exists\n");
}
}
else if (option == 2)
{
display(HEAD);
}
else if (option == 3)
{
if (HEAD == NULL)
printf("Can not delete from an empty list\n");
else if (HEAD->NEXT == NULL)
deleteAtStart(&HEAD);
else
deleteAtEnd(HEAD);
}
else if (option == 4)
{
printf("Please enter the PPSN or Name you wish to update\n");
scanf("%s", searchTerm);
updateNodeValues(HEAD, searchTerm);
}
else if (option == 5)
{
if (HEAD == NULL)
{
printf("The list is empty so this option can not be completed\n");
}
else
{
printf("Please enter the number being searched for\n");
scanf("%d", &searchNum);
foundLocation = location(HEAD, searchNum);
printf("The location is %d\n", foundLocation);
if (foundLocation < 0)
printf("This value is not in the list\n");
else if (foundLocation == 1)
deleteAtStart(&HEAD);
else if (foundLocation == length(HEAD))
deleteAtEnd(HEAD);
else
deletedAtLocation(HEAD, foundLocation);
}
}
printf("1) Add customer(Note: PPS Number must be unique).\n");
printf("2) Display all customer details to screen\n");
printf("3) Display Customer Details\n");
printf("4) Update a Customer Details\n");
printf("5) Delete Customer\n");
printf("6) Generate statistics(a – e) based on the user selecting a booking type\n");
printf("7) Print all customer details into a report file.\n");
printf("8) List all the customers in order of year born :\n");
printf("Press -1 to exit\n");
scanf("%d", &option);
}
}
void addElementAttheEnd(node* top, char studentID[])
{
node* temp;
node* temp2;
temp = (node*)malloc(sizeof(node));
printf("Please enter PPSN number\n");
scanf("%s", &temp->ppsn);
printf("Please enter your first name\n");
scanf("%s", temp->name);
printf("Please enter your surname\n");
scanf("%s", &temp->lastName);
strcpy(temp->id, studentID);
printf("Please enter the year you were born\n");
scanf("%s", &temp->year);
printf("Please enter your email\n");
scanf("%s", temp->email);
temp->NEXT = NULL;
temp2 = top;
while (temp2->NEXT != NULL)
{
temp2 = temp2->NEXT;
}
temp2->NEXT = temp;
}
void addElementAttheStart(node** top, char studentID[])
{
node* temp;
temp = (node*)malloc(sizeof(node));
printf("Please enter PPSN number\n");
scanf("%s", &temp->ppsn);
printf("Please enter your first name\n");
scanf("%s", temp->name);
printf("Please enter your surname\n");
scanf("%s", &temp->lastName);
strcpy(temp->id, studentID);
printf("Please enter the year you were born\n");
scanf("%s", &temp->year);
printf("Please enter your email\n");
scanf("%s", temp->email);
temp->NEXT = *top;
*top = temp;
}
void display(node* top)
{
node* temp;
if (top == NULL)
printf("The list is empty\n");
else
{
temp = top;
while (temp != NULL)
{
printf("==================================================================================================================\n");
printf("PPSN: %s\n", temp->ppsn);
printf("Firstname: %s\n", temp->name);
printf("Surname: %s\n", temp->lastName);
printf("Year: %s\n", temp->year);
printf("Email: %s\n", temp->email);
printf("==================================================================================================================\n");
temp = temp->NEXT;
}
}
}
void displayToFile(node* top)
{
FILE* outp;
node* temp;
if (top == NULL)
printf("The list is empty\n");
else
{
temp = top;
outp = fopen("Links.txt", "w");
if (outp == NULL)
printf("Sorry the file could not be opened\n");
else
{
while (temp != NULL)
{
fprintf(outp, "PPSN: %20s\n", temp->ppsn);
fprintf(outp, "Firstname: %20s\n", temp->name);
fprintf(outp, "Surname: %20s\n", temp->lastName);
fprintf(outp, "Year: %20s\n", temp->year);
fprintf(outp, "Email: %20s\n", temp->email);
temp = temp->NEXT;
}
fclose(outp);
}
}
}
int checkPpsn(int ppsn)
{
return 1;
}
int search(node* top, char searchID[])
{
node* temp;
if (top == NULL)
printf("The list is empty\n");
else
{
temp = top;
while (temp != NULL)
{
if (strcmp(temp->name, searchID) == 0)
{
printf("Found the element");
return 1;
}
temp = temp->NEXT;
}
}
return 0;
}
int length(node* top)
{
node* temp;
int length = 0;
if (top == NULL)
return 0;
else
{
temp = top;
while (temp != NULL)
{
length++;
temp = temp->NEXT;
}
}
return length;
}
void deleteAtEnd(node* top)
{
node* last;
node* secondlast{};
last = top;
while (last->NEXT != NULL)
{
secondlast = last;
last = last->NEXT;
}
secondlast->NEXT = NULL;
free(last);
}
void deleteAtStart(node** top)
{
node* temp;
temp = *top;
*top = temp->NEXT;
free(temp);
}
void deleteintheMiddle(node* top, char searchID[])
{
node* last;
node* secondlast{};
int removed = 0;
last = top;
while (last->NEXT != NULL)
{
if (strcmp(last->id, searchID) == 0)
{
secondlast->NEXT = last->NEXT;
free(last);
removed = 1;
break;
}
secondlast = last;
last = last->NEXT;
}
if (removed == 0)
{
printf("The node could not be found\n");
}
}
void updateNodeValues(node* top, char ID[])
{
node* temp;
int search = 0;
temp = top;
while (temp != NULL)
{
if (strcmp(temp->ppsn, ID) == 0 || strcmp(temp->name, ID) == 0)
{
printf("Please enter the ppsn you wish to update\n");
printf("Please enter new ppsn\n");
scanf("%s", temp->ppsn);
printf("Please enter new first name\n");
scanf("%s", temp->name);
printf("Please enter new surname\n");
scanf("%s", &temp->lastName);
printf("Please enter the new year you were born\n");
scanf("%s", &temp->year);
printf("Please enter your new email\n");
scanf("%s", temp->email);
search = 1;
break;
}
}
if (search == 0)
printf("The value of the ppsn was never found\n");
}
int location(node* top, char searchID[])
{
node* temp;
int location = -1;
int i = 1;
temp = top;
while (temp != NULL)
{
if (strcmp(temp->ppsn, searchID) == 0)
{
location = i;
break;
}
i++;
temp = temp->NEXT;
}
return location;
}
void deletedAtLocation(node* top, int loc)
{
node* temp;
node* prevTemp{};
int i;
temp = top;
for (i = 0; i < loc - 1; i++)
{
prevTemp = temp;
temp = temp->NEXT;
}
prevTemp->NEXT = temp->NEXT;
free(temp);
}
What I have tried:
The problem is in line 127 I keep getting an error saying cant convert argument 2 from int to char would anyone have a solution to this as I've tried changing the signs and this hasnt helped at all so far thanks very much
The function is to delete a node from a specific location and this error just keeps appearing