【发布时间】:2012-05-16 21:14:51
【问题描述】:
我正在使用 gtk+-2.0 和 gtksourceview-2.0 用 C 语言编写一个文本编辑器。我正在尝试对从缓冲区中提取的数据进行一些测试。目前我正在移动一对迭代器,然后得到一个由这些迭代器分隔的文本块。然后使用 strstr、strchr、...检查这个字符串。但是,移动迭代器、读取数据、然后执行测试的过程非常麻烦。
我还将整个文档(使用前面描述的过程)提取到gchar *。处理这些数据会更容易吗?我尝试在这些数据上使用 fgets 和 getline,但编译器抱怨:
warning: passing argument 3 of ‘fgets’ from incompatible pointer type /usr/include/stdio.h:624:14: note: expected ‘struct FILE * __restrict__’ but argument is of type ‘gchar *’
或
warning: passing argument 1 of ‘getline’ from incompatible pointer type /usr/include/stdio.h:671:20: note: expected ‘char ** __restrict__’ but argument is of type ‘gchar *’
我试过了:
int bytes_read;
int nbytes = 100;
char *my_string;
GtkTextIter start;
GtkTextIter end;
wholeDoc = gtk_text_buffer_get_text(tbuffer,&start,&end,TRUE);
my_string = (char *) malloc (nbytes + 1);
bytes_read = getline (&my_string, &nbytes, wholeDoc);
但出现以下错误:
warning: pointer targets in passing argument 2 of ‘getline’ differ in signedness /usr/include/stdio.h:671:20: note: expected ‘size_t * __restrict__’ but argument is of type ‘int *’
我正在寻找一种方法来检查,例如,通过简单地从循环索引中减去一个来检查上一行,就像每一行都是数组的一个元素一样。我怎样才能把数据放到这个表格中?请多多包涵,我正在学习。谢谢。
【问题讨论】:
标签: c gtk gtksourceview