> Create an array?

Create an array?

Posted at: 2014-12-18 
Write a function list2array(ListElement *list) that creates a array of int with all element from list. The array should contain equal many element as a list and should be allocated on the heap. The function should also handle case so that the original list is empty ( list == NULL), so should list2array returne NULL

struct ListElement {

int value;

struct ListElement *next;

};

typedef struct ListElement ListElement;

int *list2array(ListElement *list);

My code is the following:

#include

struct ListElement {

int value;

struct ListElement *next;

};

typedef struct ListElement ListElement;

int *list2array(ListElement *list){

int n;

while(sizeof(list) != '\0'){

n.value = sizeof(list);

sizeof(list)++;

}

if (sizeof(list) == '\0'){

return NULL;

}