if print out list, always returns : List is empty!, even if i put names inside
Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
struct student *dodaj_na_pocetak(struct student *head, char *ime);
void ispis(struct student *head);
struct student{
char ime[20];
struct student *next;
};
struct student *head=NULL;
int main()
{
int sranje;
char ime[20];
struct student *nova;
int x;
while(x!=0){
printf("\n----Izbornik----");
printf("\n");
printf("\n1.Dodaj");
printf("\n2.Ispis");
scanf("%d", &x);
switch(x)
{
case 1:
printf("Upisi ime: ");
scanf("%s", &ime);
dodaj_na_pocetak(head,ime);
break;
case 2:
ispis(head);
break;
}
}
scanf("%d", &sranje);
}
struct student *dodaj_na_pocetak(struct student *head, char *ime){
struct student *prvi;
prvi = (struct student *)malloc(sizeof(struct student));
strcpy(prvi->ime,ime);
prvi->next=head;
head = prvi;
return prvi;
}
void ispis(struct student *head){
struct student *temp;
temp = head;
if(temp==NULL)
{
printf("Lista je prazna");
return;
}
else
while(temp!=NULL)
{
printf("%s", temp->ime);
printf("\n");
temp=temp->next;
}
}