【发布时间】:2020-12-27 13:03:37
【问题描述】:
int8_t** FileToColorMap(char* colorfile, int* colorcount)
{
FILE* fp = fopen (colorfile, "r");
if (fp==NULL)
{
printf("no such file.");
return 0;
}
int r,g,b;
fscanf(fp, "%d", colorcount);
uint8_t* output;
output = (uint8_t *)malloc(*colorcount * sizeof(uint8_t));
for (int i = 0; i < *colorcount;i++) {
if( fscanf(fp, "%d %d %d", &r, &g, &b) != EOF ) {
// int* arr= (int *)malloc(3 * sizeof(int));
// arr[0] = r;
// arr[1] = g;
// arr[2] = b;
int arr[3] = {r,g,b};
output[i] = *arr;
} else
{
freeMap(i+1, &output);
return NULL;
}
}
fclose(fp);
return *output;
}
即使我尝试返回输出、**输出和 &ouput,这也会导致 seg 错误错误或错误 1 或其他错误。
看起来您的帖子主要是代码;请添加更多详细信息。
【问题讨论】:
-
输出 --> 从不兼容的指针类型返回
-
*output --> 从结果类型为“uint8_t **”(又名“unsigned char **”)的函数返回“uint8_t *”(又名“unsigned char *”)的不兼容指针类型;用 & [-Wincompatible-pointer-types] 获取地址
-
No seg error with &output 但中止陷阱 6 和 --> 警告:与局部变量“输出”相关的堆栈内存地址返回 [-Wreturn-stack-address]
-
请edit您的问题添加更多详细信息。所有信息都应该在问题中,而不是分散在 cmets 中。 cmets 用于提供建议或要求澄清。请写出你想用这个函数实现什么,并展示调用这个函数的代码,包括参数的定义和返回值的变量。
-
我想目的是返回一个
*colorcountRGB值的数组,即一个结构数组或一个二维数组。请在问题中澄清这一点
标签: c pointers memory-address uint8t