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

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -