Page 3 of 3 FirstFirst 123
Results 21 to 22 of 22

Thread: Problem with linked list in C

  1. #21
    Here's the working code:

    Code:
    void InsertItem(currency **list)
    {
    	currency *temp, *node;
    	temp=(currency*)malloc(sizeof(curr));
    
    	fflush(stdin);
    	printf("Vavedi valuta: ");
    	gets(temp->name);
    	printf("Vavedi kod na valutata: ");
    	gets(temp->code);
            printf("Vavedi stoinost za 1USD: ");
            scanf("%f", &temp->value);
    	temp->number=++cnt;
    	temp->next=NULL;
    	node=*list;
    	if(node!=NULL) {
    		while(node->next!=NULL)
    			node=node->next;
    		node->next=temp;
    	}
    	else
    	*list=temp;
    }
    You gotta take into account the fact that when no node is created in the beginning, there are no nodes to traverse.

  2. #22
    Senior Member
    Join Date
    Jul 2003
    Posts
    166
    Ah ... yes, of course ... such a stupid mistake ...
    BGDevS
    [gloworange]www.peaksoft.info [/gloworange]

Similar Threads

  1. Serious Problem
    By IcSilk in forum Operating Systems
    Replies: 8
    Last Post: October 30th, 2005, 11:01 PM
  2. Tips
    By XTC46 in forum Site Feedback/Questions/Suggestions
    Replies: 15
    Last Post: August 24th, 2005, 07:52 PM
  3. Parse a null delimited list of strings
    By journy101 in forum Programming Security
    Replies: 3
    Last Post: August 13th, 2003, 05:31 PM
  4. Replies: 4
    Last Post: July 24th, 2003, 08:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •