这是我的代码(带有调试打印):
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);
为什么会发生这种情况?该怎么办?
您仅为单个字符分配内存。 (顺便说一句,您也应该在 malloc 之后检查
NULL
)