Witam wszystkich,
Mam następujący kod, w którym operuje na prosty listach ale pomimo kompilacji, program nie działa. Mógłby ktoś sprawdzić co jest nie tak?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Human Human;
struct Human{
char Name;
Human *FirstSon;
};
Human *NPotomek(Human *p, unsigned int nrPotomka){
int i;
if(nrPotomka == 0){ return p;}
else {
for(i=0;i<nrPotomka;i++){
p=p->FirstSon;
}
}
return p;
}
Human *OstPotomek(Human *ost){
while(ost->FirstSon){
ost=ost->FirstSon;
}
return ost;
}
unsigned IleOsob(Human *p){
unsigned c = 0;
while(p){
c++;
p=p->FirstSon;
}
return c;
}
void DodawaniePocz(Human *head, char v){
Human *p;
p = (Human*) malloc(sizeof(Human));
p->Name = v;
p->FirstSon = head;
head = p;
}
void UsuwaniePocz(Human *head){
Human *p;
p=head;
if(p){
head = p->FirstSon;
free(p);
}
}
void LiczbaElem(Human *p){
unsigned i;
Human *tmp;
printf("Liczba elementow w liscie to: %i \n",IleOsob(p));
for(tmp=p;tmp!=NULL;tmp=tmp->FirstSon){
printf("#%i %c \n",i++,tmp->Name);
}
}
int main(){
Human *L = NULL;
DodawaniePocz(L, 'A');
DodawaniePocz(L, 'B');
DodawaniePocz(L, 'C');
DodawaniePocz(L, 'D');
LiczbaElem(L);
return 0;
}