char *s;
sprintf(s, "node %d", i);


In main you are using an uninitialized pointer.