Re: display integers in a clist



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]