Re: GtkEntry problem



Amandip wrote:

How can I retrieve the contents from a GtkEntry-field, and store and 
modify the contents as I see fit?

There are multiple options, depending on the intended kind of
modification.

1. to simply add something to the contents of the GtkEntry you may use
snprintf () like this:

gchar textbuffer [256];
snprintf (textbuffer, sizeof (textbuffer),
        "The contents of your GtkEntry are: %s",
        gtk_entry_get_text (your_GtkEntry));

2. If you want to change characters of the contents string without
changing the length of the contents string then use g_strdup ().

3. if your modification may need to change the length of the contents
(especially inserting characters) then you should provide an
appropriately (over)sized buffer to store the copy and work with and use
strncpy () / g_strlcpy ().

Rule of thumb: expected string sizes of <1000 characters are okay to be
stored in a local buffer while for buffer sizes of >1000 characters you
should allocate (and later free) a buffer via g_malloc () + g_free ().

See:
http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.html#g-strdup
http://developer.gnome.org/doc/API/2.0/glib/glib-String-Utility-Functions.html#g-strlcpy
http://developer.gnome.org/doc/API/2.0/glib/glib-Memory-Allocation.html



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]