这是我的代码(带有调试打印):
char *full_file_name = malloc(sizeof(char));
FILE *ob_file;
/*creating full file name*/
strcpy(full_file_name, file_name);
strcat(full_file_name, ".ob");
printf("\n full_file_name :%s", full_file_name);
/* -- Creating the new file and inputting data --*/
ob_file = fopen(full_file_name, "w");
printf("\n full_file_name :%s", full_file_name);
这是打印结果:
为什么会这样?该怎么办呢?
1条答案
按热度按时间rlcwz9us1#
你只为一个字符分配内存。(顺便说一句,你也应该在malloc之后检查
NULL
)