C - why cant i read a linked list in a module and return the header in main? : <p>Today I was pretty confident I would get 100% on my exam, but I wasted all my time trying to fix this error, needless to say I never finished and I'm pretty fed up with it. The idea is:</p>

<pre><code>typedef struct Poly{
    int x;
    int y
    struct Poly *next;
}Poly;

Poly *add_poly();

int main(){

Poly *a = (Poly*)malloc(sizeof(Poly));

a = add_poly(); //so this should be ret, the first 2 ints i typed should be here

printf("%dx^%d",a-&gt;x,a-&gt;y); //this works
a=a-&gt;next;
printf("%dx^%d",a-&gt;x,a-&gt;y); //this crashes.

}

Poly *add_poly(){
    Poly *temp = (Poly*)malloc(sizeof(Poly));
    Poly *ret = (Poly*)malloc(sizeof(Poly));

    temp = ret; //make sure i get to keep the header of the list?

    while(1){

        scanf("%d %d",&amp;x,&amp;y);

        temp-&gt;x=x;
        temp-&gt;y=y

        printf("%dx^%d",temp-&gt;x,temp-&gt;y);//authentication

        temp=temp-&gt;next;
        temp=(Poly*)malloc(sizeof(Poly));

        if(y==0){
            temp-&gt;x=0;
            temp-&gt;y=0;
            break;
        }
    }

    return ret;
}
</code></pre>

<p>I don't get it! I've worked with linked lists before in much more complex coding but I never had this problem, I must be missing something but I wasted 1:30 hour trying to find the mistake in the exam, and another 2 hours after I went home, same error, even if I actualy deleted and retyped every command from scratch...</p>
