EDIT:为了回答某些问题,这是订正的、仍然不可行的法典(其中多数是先开始的,但我本应明确表明,我已初步提出档案点等)。 再说一遍,如果我要么在(a)项之前加上一封信,要么完全删除(a)项,那就行了。
FILE *outfile;
char *outfilename;
outfilename = (char *)malloc(FILENAME_MAX*sizeof(char));
strcpy(outfilename, "outfile.txt");
outfile = fopen(realoutfilename, "w");
/* If this is uncommented, there isn t a segfault
if(realoutfile!=NULL && imoutfile!=NULL){
fprintf(outfile, "
");
fseek(outfile,0,SEEK_SET);
}
*/
gauss = (double*) calloc(points, sizeof(double));
/* Maths and stuff */
if(outfile!=NULL){
for(i=0;i<points;i++){
/* this prints fine */
printf(outfile, "%g,
", gauss[i]);
/* Seg fault is here */
fprintf(outfile, "%g,
", gauss[i]);
}
}
fclose(outfile);
free(outfile);
• 编辑:
gcc main.c -lm - Wall - Wextra - Werror - Wshadow -g -o main
为了澄清,它没有达到功能的结束,因此它没有放弃它坠毁。 坠毁时正试图在案卷中写上 lo。
我检查一下,正如我所说的那样,支出是拖长或流入不足的,我可以打印产出,但书面文件是没有的。 如果我试图用简单的话说话,就失败了。
背书是(不熟悉 g,认为它可能有助于):
#0 0xff15665c in _malloc_unlocked () from /lib/libc.so.1
#1 0xff15641c in malloc () from /lib/libc.so.1
#2 0xff1a8c80 in _findbuf () from /lib/libc.so.1
#3 0xff1a8f0c in _wrtchk () from /lib/libc.so.1
#4 0xff1ad834 in _fwrite_unlocked () from /lib/libc.so.1
#5 0xff1ad798 in fwrite () from /lib/libc.so.1
#6 0x000128ac in gaussian ()
#7 0x00010f78 in main ()
任何帮助都将受到高度赞赏。