Thread: linked list function test

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    8

    linked list function test

    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);
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    while(choice!=2)
    {
    You're missing your matching closing braces.

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM