Im working on putting a link list together and I've removed all the code that isn't relevant..I have lots of cases to add but I'm getting errors on the add_last function(which places a new record at the end of the list) the errors say I have declaration syntax error at the first line of the function(add_last)...If you have any suggestions I would love to see them.. thanks
Code:
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
#include <conio.h>
typedef struct master
{
char name[20];
float expense;
struct master *p_next;
}MASTER;
void intro(void);
char ragain(void);
void signoff(void);
void pause(void);
MASTER* populate(void);
MASTER* space(void);
MASTER* add_last(MASTER *p_current,MASTER *p_newest);
int main(void)
{
int choice=1;
char input = 'y';
MASTER *p_first;
MASTER *p_current;
MASTER *p_newest;
clrscr();
intro();
while(input == 'Y' || input == 'y')
{
p_first=populate();
p_current=p_first;
while(choice!=2)
{
clrscr();
puts("\nPlease enter a number from the menu choices and press <enter>.");
puts("1. Add a new record to the end of the list.\n");
/*puts("3. Insert a new record into the list.\n");
puts("4. Delete a record from the list.\n");*/
puts("2. Exit the program.\n");
scanf("%d",&choice);
switch(choice)
{
case 1: /*2*/
p_newest=populate();
p_current=add_last(p_current,p_newest);
break;
case 2:
puts("Exit program\n");
exit(1);
break;
default:
puts("\nYou have entered an invalid option,please try again.");
break;
}
input=ragain();
}
signoff();
pause();
return 0;
} /* End of Main */
***************************************************/
MASTER* add_last(MASTER *p_current,MASTER *p_newest)
{
while(p_current->p_next!=NULL)
{
p_current=p_current->p_next;
}
p_current->p_next=p_newest;
return(p_newest);
}
/***************************************************/
MASTER* space(void)
{
MASTER *p_temp;
p_temp=(MASTER*)malloc(sizeof(MASTER));
if(!p_temp)
{
printf("Your request for space has been denied");
exit(1);
}
return(p_temp);
}
/***************************************************/
MASTER* populate(void)
{
MASTER *p_temp;
float expenses;
p_temp=space();
printf("Please enter an emloyee name:");
fflush(stdin);
gets(p_temp->name);
puts("\n\nPlease enter the employee expenses:");
scanf("%f",&expenses);
p_temp->expense=expenses;
p_temp->p_next='\0';
return(p_temp);
}