Δημοσιεύτηκε: 29 Ιουν 2011, 05:08
από Star_Light
Κώδικας: Επιλογή όλων
#include<stdio.h>
#include<stdlib.h>

typedef struct
{
int id;
struct customer *next;
} customer;

int main ()
{
customer *head , *one;
customer *two;

head = NULL;

{
head= calloc(1,sizeof(customer));
head->id=1;
head->next = NULL;
}

one= calloc(1,sizeof(customer));
one->id=2;
one->next=NULL;
head->next=one;

two=calloc(1,sizeof(customer));
two->id=3;
two->next=NULL;
one->next=two;


customer *helper=head;

while(helper!=NULL)
{
printf("%d %d %d",head->id , one->id , two->id);
helper=helper->next;
}

free(head);
free(head->next);
free(one->next);

if(head->id)
printf("H free dn ekane kala tin douleia tis \n");
else
printf("H mnimi eleutherwthike!");


return 0;
}



Να και ο δικος μου! Απλα εμφανιζει λογικο σφαλμα δηλαδη τυπωνει το 1 2 3 (3 φορες συνολικα)

1 2 3 1 2 3 1 2 3
Κατα τα αλλα μου βγαζει μηνυμα οτι η μνημη ελευθερωθηκε επιτυχως! Ελπιζω αυτη τη φορα.... να τα πηγα καλα!
το one->next=two; που εχω βαλει ισως ειναι λαθος... αλλα ετσι το καταλαβαινα τελεια ρε γ*****!
Δοκιμασα να βαλω head->net=two; και οντως μου τα εβγαλε 2 φορες 1 2 3 1 2 3 (οχι 3 οπως πριν)

EDIT: Λύθηκε αλλάζοντας μεσα στην while την printf ετσι

Κώδικας: Επιλογή όλων
printf("%d \n",helper->id);


;)