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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -