奇怪的分段错误 [英] Weird segmentation fault

查看:88
本文介绍了奇怪的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FILE * msgFile = fopen(" MessageFile.log"," w");


.....

fprintf(msgFile ,OK,All Done.\ n;)

^

^

这是我的计划结束,但是它仍然是错误的。

任何想法?

FILE *msgFile = fopen("MessageFile.log", "w");

.....
fprintf(msgFile, "OK, All Done.\n");
^
^
Thats at the end of my program, and yet it still seg faults.
any Ideas?

推荐答案

2月26日晚上9:48, "费诺" < Collin.Moer ... @ gmail.comwrote:
On Feb 26, 9:48 pm, "Feanor" <Collin.Moer...@gmail.comwrote:

FILE * msgFile = fopen(" MessageFile.log"," w");


....

fprintf(msgFile,OK,All Done.\ n);

^

^

多数民众赞成在我的计划结束时,但它仍然存在错误。


任何想法?
FILE *msgFile = fopen("MessageFile.log", "w");

....

fprintf(msgFile, "OK, All Done.\n");
^
^
Thats at the end of my program, and yet it still seg faults.

any Ideas?



你检查了fopen()的返回值吗?尝试发布一个小的,完整的,可编辑的程序来展示有问题的行为。


Robert Gamble

Did you check the return value of fopen()? Try posting a small,
complete, compilable program that exhibits the problematic behavior.

Robert Gamble

< br>

在文章< 11 ********************* @ v33g2000cwv.googlegroups中。 com>,

Feanor< Co ************ @ gmail.comwrote:
In article <11*********************@v33g2000cwv.googlegroups. com>,
Feanor <Co************@gmail.comwrote:

> FILE * msgFile = fopen(" MessageFile.log"," w");
>FILE *msgFile = fopen("MessageFile.log", "w");


> fprintf(msgFile,OK,All Done.\ n);
>fprintf(msgFile, "OK, All Done.\n");


>这是我程序结束时的问题,但它仍然存在错误。
>Thats at the end of my program, and yet it still seg faults.


>任何想法?
>any Ideas?



您是否检查过fopen()是否返回NULL?


-

如果你撒谎到编译器,它将报复。 - Henry Spencer

Did you check to see if fopen() returned NULL ?

--
If you lie to the compiler, it will get its revenge. -- Henry Spencer


Feanor写道:
Feanor wrote:

FILE * msgFile = fopen(" MessageFile.log" ,w,...

....

fprintf(msgFile,OK,All Done.\ n);

^

^

这是我的程序结束时,但它仍然有问题。


任何想法?
FILE *msgFile = fopen("MessageFile.log", "w");
....
fprintf(msgFile, "OK, All Done.\n");
^
^
Thats at the end of my program, and yet it still seg faults.
any Ideas?



鉴于您显然不愿意提供更多详细信息,如果可能是b $ b,则可以使用完整,可编译的程序来展示您的问题,
我们除了做出疯狂的猜测之外别无他法。正如其他人说的那样,在使用

相关指针之前,检查fopen是否确实已经成功。

Given your apparent reluctance to provide more details and, if
possible, a complete, compilable program that exhibits your problem,
there''s not much we can do other than make wild guesses. As others
have said, check whether fopen really does suceed, before using the
associated pointer.


这篇关于奇怪的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆