Problem with linked list in C
Hi,
When I call the function Print it loops in endless cycle. I can't solve this problem. Hope somebody can help. Here is the code:
Code:
#include <stdio.h>
typedef struct curr
{
char name[50];
char code[3];
float value;
int number;
struct curr *next;
}currency;
currency *start_ptr = NULL;
int cnt = 0;
void Print(currency *list)
{
currency *temp = list;
if (temp!=NULL)
while(temp!=NULL)
{
printf("%d.\t%s\t%s\t%f\n", temp->number, temp->name, temp->code, temp->number);
temp->next;
}
else
printf("Spisakat e prazen.\n");
}
void InsertItem(currency **list)
{
currency temp;
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;
*list=&temp;
}
void main()
{
currency *list = NULL;
InsertItem(&list);
Print(list);
}