Re: [gtk-list] Re: Heisenberg was right?
- From: John Looney <John Looney hos horizon ie>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Heisenberg was right?
- Date: Thu, 11 Jun 1998 09:47:31 +0100
Rouat manu wrote:
> char *convert_to_char(double data)
> {
> char *c;
> static char buffer[10];
>
> sprintf (buffer, "%g", data);
> if(data==N_A)
> sprintf (buffer, "N/A");
> c=buffer;
> /* printf("buffer:%g\n",data); */
>
> return c;
> }
Ooops. Returning the address of the stack is a bad idea. Something along
the lines of:
if(data==N_A)
sprintf(buffer, "N/A");
else
c=strdup(buffer);
return c;
Is a better idea. strdup copies the string & takes care of memory
allocation. Also, seeing as the function is small, there is no problem
allocating a lot more than 10 bytes for the buffer.
Kate
--
"I am Grey. I stand between the candle and the star.
We are Grey. We stand between the darkness and the light."
John "Kate" Looney, Horizon Open Systems. Sun Microsystems distributor and
Support centre. Hotline: [+353 1 8055700] Web http://www.hos.horizon.ie/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]