[英]Cast to pointer from integer of different size
I'm trying to insert int as value to gtree
, which comes from glib
. 我正在尝试将int作为值插入
gtree
,它来自glib
。 I don't how should I assign and insert it. 我不应该如何分配和插入它。 Here you can see what I have tried:
在这里你可以看到我尝试过的东西:
void readFilec(GTree *tree)
{
FILE *fp = fopen("cfg/file.csv", "rb" );
char * line = NULL;
size_t len = 0;
ssize_t read;
if (fp == NULL)
exit(EXIT_FAILURE);
char *p1;
int p2;
while ((read = getline(&line, &len, fp)) != -1)
{
printf("%s", line);
p1 = strtok(line, "|");
p2 = (int)atoi(strtok(NULL, "|"));
g_tree_insert(tree,(gpointer *) g_strdup(p1), (gpointer *) p2);
printf("-%s%d ", p1, p2);
}
if (line)
free(line);
//exit(EXIT_SUCCESS);
}
The file which I read looks like that: 我读的文件看起来像那样:
cfg/file.csv
AA1.E|1
AA2.E|2
尝试删除gpointer之后的*,因为它已经是一个空白*并在p2前添加'&'以获得它的地址。
g_tree_insert(tree, (gpointer) g_strdup(p1), (gpointer) &p2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.