使用fopen函数时出现分段错误。如果我使用不在结构中的file
,则不会发生错误。我猜segfault来自于使用来自结构的file
int main(int argc, char **argv)
{
t_paint *paint;
if (argc != 2)
{
write (1, "Error: argumentn", 16);
return (1);
}
paint->file = fopen(argv[1], "r");
if (paint->file == NULL || parsing(paint))
{
write(1, "Error: Operation file corruptedn", 32);
free(paint->map);
fclose(paint->file);
return (1);
}
output(paint);
fclose(paint->file);
free(paint->map);
return (0);
}
t_paint
typedef struct s_paint
{
char *map;
int widthMap;
int heightMap;
float firstX;
float firstY;
float w;
float h;
char typeFile;
char background;
char filler;
FILE *file;
} t_paint
t_paint *paint;
if (argc != 2)
{
write (1, "Error: argumentn", 16);
return (1);
}
paint->file = fopen(argv[1], "r");
您修改了paint
指向的对象的file
成员。但paint
不指向任何东西——您从未为其分配值或创建t_paint
的实例。