转换的字符数组一个const gchar * [英] converting an array of characters to a const gchar*

查看:213
本文介绍了转换的字符数组一个const gchar *的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符数组,其中包含一个字符串:

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';

我在找这个字符串作为参数传递给 gtk_text_buffer_insert 函数,以将其插入到 GtkTextBuffer 。我想不通的是如何将其转换为一个常量gchar * ,这是 gtk_text_buffer_insert 预计为第三个参数。

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.

任何人能帮助我吗?

推荐答案

gchar 就是的typedef 字符和数组为const指针的转换是隐式的,所以你可以通过它:

gchar is just a typedef for char and the conversion from arrays to const pointers is implicit, so you can just pass it:

someFunctionExpectingConstGcharPointer(buf);

请注意,您也可以直接用字符串初始化数组:

Note that you can also directly initialize arrays with string literals:

char buf[MAXBUFLEN] = "foo";

这篇关于转换的字符数组一个const gchar *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆