I am working on a program in C right now that deals with linked lists. Here is the assignment statement:
"Write a C program called Assignment4.c, that creates a linked list of Customer data. Each entry in the list is to have the customer’s last name, first name, id (int), balance (float), and a pointer to the next customer data. Create a struct for the Customer first. Then create a pointer (“head”) that points to the first element in the linked list (initially NULL), as a global variable."
There are also a few functions we are supposed to define:
int insertAtIndex
int size
void displayLinkedList
int removeCustomer
struct Customer * searchCustomer
and of course, int main
So I started at the top, and right now I have code for the first three functions, but I am not sure my code is right at all, because I can't compile my code since I haven't written the main method. I am having a few compilation errors, however, including the fact that in my displayLinkedList function the variables last_name, first_name, etc. are undeclared. The reason I have them undeclared like that is that I don't know how to access the variables from my linked list and print them. How do I do this?
Also, are the other two functions that I have code for correct at all?
And last, I am confused about how to do the remove_Customer function. Can someone help me with the pseudo code for this function?
Thank you guys in advance for helping me with this!
Here is what I have so far:
/****
Assignment4.c
****/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
typedef struct customer_data CUSTOMER_DATA;
struct customer_data
{
char last_name;
char first_name;
int id;
float balance;
CUSTOMER_DATA *next;
};
CUSTOMER_DATA * customer_head = NULL;
CUSTOMER_DATA * customer_tail = NULL;
//struct customer_data * BuildList(newlastname, newfirstname, newid, newbalance)
int insertAtIndex(char * lastname, char * firstname, int id, float balance, int index)
{
CUSTOMER_DATA * newcustomer;
if ((newcustomer = malloc(sizeof(CUSTOMER_DATA))) == NULL)
{ abort(); }
newcustomer->last_name = *lastname;
newcustomer->first_name = *firstname;
newcustomer->id = id;
newcustomer->balance = balance;
newcustomer->next = NULL;
if (!customer_head) customer_head = newcustomer;
else customer_tail->next = newcustomer;
customer_tail = newcustomer;
return index;
}
int size()
{
int size;
size = sizeof(CUSTOMER_DATA);
return size;
}
void displayLinkedList( )
{
int i;
for (i; i < sizeof(CUSTOMER_DATA); i++)
{
printf("Last Name: ", last_name);
printf("First Name: ", first_name);
printf("Customer ID: ", id);
printf("Customer Balance: $ ", balance);
}
}