[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: display integers in a clist
- From: Don Dudley <ddudley mybearcreek com>
- To: Gus Koppel <gtk spamkiller bytechase cx>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: display integers in a clist
- Date: 30 Jan 2004 07:07:26 -0700
On Fri, 2004-01-30 at 01:13, Gus Koppel wrote:
> parthasarathi s a wrote:
>
> > You could use the C string libraries' sprintf() function to print the
> > "number" into a string.-partha
> >
> > "Thomas Keaney" <se40319@cs.may.ie> wrote:
> > > Would anyone know of how to convert an integer to a
> > > character(convert 1 to '1') as I want to display this in a clist.
> > > Also, I want to concatenate this to a word(for example MEMORY 1
> > > ),where the word is MEMORY and the integer I want to display is 1 in
> > > the clist. Thanks in advance.
>
> A note in case you want to avoid programming bugs and safety hazards,
> commonly around by the term "buffer overflows", for your application:
>
> *NEVER* use sprintf ()! Always use snprintf () instead!
>
> Failing to do so is the no. 1 reason for buffer overflows and related,
> easily avoidable software failures. They are not an issue of novice
> programmers only.
>
> See
> http://mail.gnome.org/archives/gtk-app-devel-list/2003-October/msg00344.html
> for further information on that.
>
Even better, use the glib function g_strdup_printf(). It mallocs the
space for your new string for you, and prevents overflow. Make sure you
free your new string when you're done with it. :
gint num = 1;
gchar *word = "MEMORY";
gchar *newstr;
newstr = g_strdup_printf("%s %d", word, num);
See:
http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.html
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]