need help!!!

This is a discussion on need help!!! within the C Programming forums, part of the General Programming Boards category; Code: /*linked list*/ #include<stdio.h> #include<stdlib.h> struct NODE { int number; struct NODE *next; }; int search_value(struct NODE*llist,int num); void append_node(struct ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    2

    Exclamation need help!!!

    Code:
    /*linked list*/
    #include<stdio.h>
    #include<stdlib.h>
    
    struct NODE
    {
    	int number;
    	struct NODE *next;
    };
    int search_value(struct NODE*llist,int num);
    void append_node(struct NODE*llist,int num);
    void display_list(struct NODE*list);
    void delete_node(struct NODE*list,int num);
    
    int main(void)
    {
    	int num=0;
    	int input=1;
    	int retval=0;
    	struct NODE*llist;
    
    	llist=(struct NODE*)malloc(sizeof(struct NODE));
    	llist-> number=0;
    	llist-> next=NULL;
    
    	while(input!=0)
    	{
    		printf("\n --MENU SELECTION--\n");
    		printf("0) QUIT \n");
    		printf("1) INSERT \n");
    		printf("2) DELETE \n");
    		printf("3) SEARCH \n");
    		printf("4) DISPLAY \n");
    		scanf("%d",&input);
    
    		swith(input)
    		{
    			case 0:
    				default;
    				printf("GOOD BYE...\n");
    				input=0;
    				break;
    			case 1:
    				printf("Your choice: 'Insertion' \n");
    				printf("Enter the value which should be inserted:");
    				scanf("%d",num);
    				append_node(llist,num);
    				break;
    			case 2:
    				printf("Your choice: 'Deletion' \n");
    				printf("Enter the value to be deleted:");
    				scanf("%d",&num);
    				delete_node(list,num);
    				break;
    			case 3:
    				printf("Your choice: 'Search' \n");
    				printf("Enter the value you want to search:");
    				scanf("%d",&num);
    				if(retval=search_value(llist,num))==-1)
    				  printf("value '%d' not found \n",num);
    				else
    				  printf("value '%d' located at position '%d' \n",num, retval);
    				break;
    			case 4:
    				printf("Your choice: 'Display' \n");
    				display_list(llist);
    				break;
    
    		}
    	}
    		free(llist);
    		return(0);
    }
    void display_list(struct NODE*llist)
    	{
    		while(llist->next!=NULL)
    		{
    			printf("%d",llist->number);
    			llist=llist->next;
    		}
    			printf("%d",list->number);
    	}
    void append_node(struct NODE*llist, int num)
    	{
    		while(llist->next!=NULL)
    		llist=llist->next;
    
    		llist->next=(struct NODE *)malloc(sizeof(struct NODE));
    		llist->next->number=num;
    		llist->next->NUL;
    	}
    void delete_node(struct NODE *list,int num)
    	{
    		struct NODE *temp;
    		temp=(struct NODE *)malloc(sizeof(struct NODE));
    		if(llist->number==num)
    		{
    			temp=llist->next;
    			free(llist);
    			llist=temp;
    		}
    		else
    		{
    			while(llist->next->number!=num)
    			llist=llist->next;
    			temp=llist->next->next;
    			free(llist->next);
    			llist->next=temp;
    		}
    	}
    int search_value(struct NODE*llist,int num)
    	{
    		int retval=-1;
    		int i=1;
    		while(llist->next!=NULL);
    		{
    			if(llist->next->number==num)
    			{
    				return(i);
    			}
    			else
    			i++;
    			llist=list->next;
    		}
    			return retval;
    	}

  2. #2
    Registered User
    Join Date
    Feb 2011
    Posts
    2
    hey guys i need yall to help me to debugg this code i have no idea whats wrong with it.
    tried everything pls help!!!

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    In future, how about a brief description of the *actual problem* in your thread titles. A lot of people won't read "please help" because it's totally over-used.

    So... how about you tell us exactly what problems you're having....

  4. #4
    Bit Fiddler
    Join Date
    Sep 2009
    Posts
    67
    Read the compiler error messages. In this case they would be quite straight forward.

    Good luck.

  5. #5
    Registered User
    Join Date
    Feb 2011
    Posts
    5
    i compiled the code on my machine and there r many problems. here's the compiler's warnings:
    Code:
    cc "C file.c"
    C file.c: In function ‘main’:
    C file.c:36: error: expected ‘;’ before ‘{’ token
    C file.c:60: error: ‘else’ without a previous ‘if’
    C file.c:63: error: case label not within a switch statement
    C file.c: At top level:
    C file.c:70: warning: data definition has no type or storage class
    C file.c:70: warning: parameter names (without types) in function declaration
    C file.c:70: error: conflicting types for ‘free’
    C file.c:71: error: expected identifier or ‘(’ before ‘return’
    C file.c:72: error: expected identifier or ‘(’ before ‘}’ token
    C file.c: In function ‘display_list’:
    C file.c:80: error: ‘list’ undeclared (first use in this function)
    C file.c:80: error: (Each undeclared identifier is reported only once
    C file.c:80: error: for each function it appears in.)
    C file.c: In function ‘append_node’:
    C file.c:89: error: ‘struct NODE’ has no member named ‘NUL’
    C file.c: In function ‘delete_node’:
    C file.c:95: error: ‘llist’ undeclared (first use in this function)
    C file.c: In function ‘search_value’:
    C file.c:122: error: ‘list’ undeclared (first use in this function)
    i think u should fix those problems first and see if it works.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21