C problem

poruka: 1
|
čitano: 746
|
moderatori: Lazarus Long, XXX-Man, vincimus
1
+/- sve poruke
ravni prikaz
starije poruke gore
7 godina
neaktivan
offline
C problem

jel moze neko rec sta tu ne valja?

#include <stdio.h>
#include <stdlib.h>

typedef struct student
{
int data;
char ime[20+1];
char prezime[30+1];
unsigned int mbr;
double prosjek;
struct student *next;
struct student *prev;
} student_t;

student_t *head = NULL;


student_t *create_student(int x)
{
student_t *pstu = (student_t *) malloc(sizeof(student_t));

pstu->data = x;
pstu->prev = NULL;
pstu->next = NULL;
return pstu;

if(pstu == NULL)
{
printf("Nisam uspio alocirati memoriju! \n");
return NULL;
}
printf("Ime? ");
scanf(" %s", pstu->ime);
printf("Prezime? ");
scanf(" %s", pstu->prezime);
printf("MBR? ");
scanf(" %d", &(pstu->mbr));
printf("Prosjek? ");
scanf(" %lf", &(pstu->prosjek));

pstu->next = NULL;

return pstu;
}

void add_to_list(student_t *pstudent)
{
if(head == NULL)
{

head = pstudent;
}
else
{
student_t *current = head;
while(current->next != NULL)
{
current = current->next;
}
current->next = pstudent;
}
}

void InsertAtHead(int x) {
student_t *pstu = create_student(x);
if(head == NULL) {
head = pstu;
return;
}
head->prev = pstu;
pstu->next = head;
head = pstu;
}


void InsertAtTail(int x) {
student_t *current = head;
student_t *pstu = create_student(x);
if(head == NULL) {
head = pstu;
return;
}
while(current->next != NULL) current = current->next;
current->next = pstu;
pstu->prev = current;
}

void print_list()
{
printf("\n *** STUDENTSKA LISTA START *** \n");
student_t *current = head;
while(current != NULL)
{
printf("Ime: %s\n", current->ime);
printf("Prezime: %s\n", current->prezime);
printf("MBR: %d\n", current->mbr);
printf("Prosjek: %lf\n", current->prosjek);
current = current->next;
}
printf("\n *** STUDENTSKA LISTA END *** \n");
}

void ReversePrint() {
student_t *current = head;
if(current == NULL)
return; 
while(current->next != NULL)
{
current = current->next;
}

printf("Reverse: ");
while(current != NULL)
{
printf("%d ",current->data);
current = current->prev;
}
printf("\n");
}

int main()
{
char ima_jos = 'd';
while((ima_jos == 'd') || (ima_jos == 'D'))
{
student_t *pstudent = create_student();
add_to_list(pstudent);

printf("Ima jos? (d/n)");
scanf(" %c", &ima_jos);
}
printf("Upisani studenti: \n");
print_list();

return 0;


head = NULL;

InsertAtTail(); print_list(); ReversePrint();

 
0 0 hvala 0
1
Nova poruka
E-mail:
Lozinka:
 
vrh stranice