Proper way to return a string in C -
i have following code:
char* get_address_string(package* pkg){ char *c; sprintf(c, "%02x:%02x:%02x:%02x:%02x:%02x", pkg->address[0], pkg->address[1], pkg->address[2], pkg->address[3], pkg->address[4], pkg->address[5]); return c; }
the code works fine. however, know not proper way return string in c. receiving warning "c used uninitialized in function".
what proper way write function in c?
c
pointer, no memory allocated. return value ok, that's how can done in c.
but need allocate memory.
Comments
Post a Comment