Lista jednokierunkowa (stack overflov (?))

0

Witam
36 21 F:\Documents and Settings\Admin\Moje dokumenty\sitkuj.c [Warning] assignment from incompatible pointer type [enabled by default]
to mi wyskakuję po skompilowaniu programu , mogłby mi ktoś powiedzieć czemu i ewentualnie poprawić kod:

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

typedef struct STT{
         int key;
         struct Lista *next;}ell, *stos;

stos push(int x, stos head){
      stos nowy = (stos)malloc(sizeof(ell));
      nowy->key=x;
      nowy->next=head;
      head=nowy;
      return head;
}


void wypisz(stos head){
      if (head!=NULL){
         wypisz(head->next);
         printf("%d\n",head->key);
         }
}

stos pop(stos head){
      stos temp = head->next;
      free(head);
      return temp; 
}


void sitkuj(stos head, int valju, int n){
     stos temp = head;
     int j = valju;
     for(j;j<=n;temp=temp->next, j++) if (j%valju==0) temp->key = 0;
     }


int main(){
    
     FILE *plik;
     stos head = NULL;
     int n;
     int i;
     int current;
     scanf("%d",&n);
     
     
     if ((plik=fopen("se.txt", "w"))==NULL) {
        printf ("Nie moge otworzyc pliku se.txt do zapisu!\n");
        getch();
        exit(1);
     }
     
     for(i=n;i>=2;i--) head = push(i,head); //wypelnienie listy wartosciami od n do 2
     
     
     for(i=2;i<=n;i++){//czesc glowna prorgamu
                      current = head->key;
                      if(current!=0){
                                     fprintf (plik, "%d\n", current);
                                     sitkuj(head, current, n);
                      }
                      head = head->next;
     }
     fclose (plik);
     getch();
     return 0;
}
0
temp->key = NULL;
0
prog.c: In function ‘push’:
prog.c:13:17: error: assignment from incompatible pointer type [-Werror]
prog.c: In function ‘wypisz’:
prog.c:21:10: error: passing argument 1 of ‘wypisz’ from incompatible pointer type [-Werror]
prog.c:19:6: note: expected ‘stos’ but argument is of type ‘struct Lista *’
prog.c: In function ‘pop’:
prog.c:27:19: error: initialization from incompatible pointer type [-Werror]
prog.c: In function ‘sitkuj’:
prog.c:36:6: error: statement with no effect [-Werror=unused-value]
prog.c:36:21: error: assignment from incompatible pointer type [-Werror]
prog.c: In function ‘main’:
prog.c:59:28: error: assignment from incompatible pointer type [-Werror]
cc1: all warnings being treated as errors

Przypisujesz wskaźnik na struct STT do wskaźnika na struct Lista i odwrotnie. Dodatkowo to samo j w for jest niepotrzebne. Poza tym program działa bo C troszkę olewa to, że typy się niby nie zgadzają - wskaźnik to wskaźnik i wszystko się niejawnie konwertuje. Logiczności samego kodu nie analizowałem.

1 użytkowników online, w tym zalogowanych: 0, gości: 1