0

I have the following struct I would like to initialize:

typedef struct Node {
struct Node *next;
int data;
}Node;

And the following function prototype I need to use to initialize it(using dynamic memory allocation):

void initialize_node(Node *in){
 in= calloc(1, sizeof(Node));
}

After the function call ends, in is still not initialized. How do i fix this?

CMonster
  • 1
  • 1
  • Can you update your description to include what you have so far for initialize_node and describe which part specifically you are having a problem with? – Philip Brack Oct 18 '17 at 01:56
  • First, `Node *next;` --> `struct Node *next;`. And With this signature, you can not set an object dynamically allocated to the caller's pointer. – BLUEPIXY Oct 18 '17 at 01:57
  • Please do not repeat the same [question](https://stackoverflow.com/questions/46782361/setting-the-value-in-a-struct-pas-by-value-issue-c90). – BLUEPIXY Oct 18 '17 at 02:01
  • I've updated the question, the missing "struct" was a typo @BLUEPIXY – CMonster Oct 18 '17 at 02:07
  • What are your issues? Please show us a [Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). In this specific case @BLUEPIXY has clearly pinned down what your issue is. – Costantino Grana Oct 18 '17 at 02:08
  • @BLUEPIXY my bad – krpra Oct 20 '17 at 00:13

0 Answers0