#include #include #include #include struct lijst{ double getal; struct lijst* volgend; }; void split(struct lijst *hoofd, int** n, float** frac); int telAantal(struct lijst *hoofd); double geefGetal(struct lijst* hoofd, int i); void printUit(struct lijst *hoofd); void voegToeS(struct lijst **hoofd,float j); int main(void){ int i; int *n = NULL; float *frac = NULL; struct lijst *lijst1 = NULL; voegToeS(&lijst1,5.8); voegToeS(&lijst1,8.4); voegToeS(&lijst1,9.23); voegToeS(&lijst1,1.52); voegToeS(&lijst1,0.4); printUit(lijst1); split(lijst1,&n,&frac); for(i=0; i<5;i++) printf("\n%d \t %.3lf",n[i],frac[i]); while(1); return 0; } void split(struct lijst *hoofd,int **n, float **frac){ int i,aantal = telAantal(hoofd); double *ptr; *frac = (float*) malloc(sizeof(float *) * aantal); *n = (int*) malloc(sizeof(int *) * aantal); for(i=0; i < aantal; i++){ ptr = (double *)malloc(sizeof(double)); (*frac)[i] = (float)modf(hoofd->getal,ptr); (*n)[i] = (int)(*ptr); printf("\nTEST: %d , %.1f",(*n)[i],(*frac)[i]); hoofd = hoofd->volgend; } printf("\nend test\n\n"); } int telAantal(struct lijst *hoofd){ int i = 0; while(hoofd != NULL){ hoofd = hoofd->volgend; i++; } return i; } void voegToeS(struct lijst **hoofd,float j){ struct lijst *hulp = *hoofd; struct lijst *nieuw = (struct lijst *) malloc ( sizeof(struct lijst*)); nieuw->getal = j; nieuw->volgend = NULL; if(hulp == NULL) *hoofd = nieuw; else { while(hulp->volgend != NULL) hulp = hulp->volgend; hulp->volgend = nieuw; } } void printUit(struct lijst *hoofd){ while(hoofd != NULL) { printf("\n%.3lf\t\t%p",hoofd->getal,hoofd->volgend); hoofd = hoofd->volgend; } }