struct nodeStruct {
int value;
struct nodeStruct *next;
}
struct nodeStruct* List_createNode(int item) {
nodeStruct* tempNode;
tempNode->value = item;
nodeStruct* node = malloc ( sizeof(tempNode) );
return nodeStruct;
}
This is what I have so far, How would I allocate memory for a new node and initalize the value, then return a pointer to it? Not sure if I have the right approach.
Correction:
struct nodeStruct* List_createNode(int item) {
struct nodeStruct node* = (struct nodeStruct *) malloc(sizeof(struct nodeStruct));
if (node == NULL) {return NULL;}
node->value = item;
return node;
}
Would this return a pointer to a new node?