Re: a curious questions about return type



Andrew Poelstra wrote:

questions? wrote:
char * get_month(double number){
char month[10];
blah blah

return month
};
[...]

Just replace
char month[10];
with
char *month = malloc(10);

Just be sure to #include <stdlib.h>, and to document that the calling
function needs to handle the deallocation (this is important because any
code could become a library if need be).

And be sure to document that the caller is responsible for free()ing the
returned buffer when done, in order to prevent memory leaks.

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@xxxxxxxxx>


.



Relevant Pages