I've got an array of characters which contains a string:
char buf[MAXBUFLEN];
buf[0] = 'f';
buf[1] = 'o';
buf[2] = 'o';
buf[3] = '\0';
I'm looking to pass this string as an argument to the gtk_text_buffer_insert
function in order to insert it into a GtkTextBuffer
. What I can't figure out is how to convert it to a const gchar *
, which is what gtk_text_buffer_insert
expects as its third argument.
Can anybody help me out?
gchar
is just atypedef
forchar
and the conversion from arrays to const pointers is implicit, so you can just pass it:Note that you can also directly initialize arrays with string literals:
Well, lets see. GTK+ reference manual says:
and
This means, that a char* can be used in place of gchar*.
Though I have not used gtk_text_buffer_insert() , but in other gtk+ functions that require gchar*, char* has worked flawlessly.
Hope it was helpful.
This may be really late, but in case anyone else stuck with this comes here with a google:
should do the trick. The problem is the null character on the end. So by sending in the string length you send in all characters before the null character.