Re: a curious questions about return type
- From: Kenneth Brody <kenbrody@xxxxxxxxxxx>
- Date: Sun, 23 Apr 2006 14:05:51 -0400
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>
.
- Follow-Ups:
- Re: a curious questions about return type
- From: Richard Bos
- Re: a curious questions about return type
- References:
- a curious questions about return type
- From: questions?
- Re: a curious questions about return type
- From: Andrew Poelstra
- a curious questions about return type
- Prev by Date: Re: car park question!
- Next by Date: Re: Code quality
- Previous by thread: Re: a curious questions about return type
- Next by thread: Re: a curious questions about return type
- Index(es):
Relevant Pages
|