stdout没开? [英] stdout not open?

查看:45
本文介绍了stdout没开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试


fprintf(文件,报告文件%s \ n,sMF-> fileName)时;


我得到核心转储。如果将fprintf更改为

sprintf并使用字符串缓冲区作为第一个

参数,则此方法正常工作。


它看起来比如标准描述符并不是真的开放。


这是Sun / Solaris

SunOS usrts005 5.8 Generic_117350-08 sun4u sparc SUNW,Ultra- 5_10


使用gcc


从/vobs/edgedsp_tools/solaris/lib/gcc-lib/sparc-sun-solaris2.7阅读规格/3.0.4/specs

配置:../../ gcc-3.0.4 / configure --prefix = / vobs / edgedsp_tools / solaris

线程模型:posix

gcc版本3.0.4

-

Randy Yates

索尼爱立信移动通信
美国北卡罗来纳州三角研究园
ra ********* @ sonyericsson.com ,919-472-1124

解决方案

Randy Yates写道:

当我尝试fprintf(文件,&qu ot;文件报告%s \ n",sMF-> fileName);

我得到核心转储。如果将fprintf更改为sprintf并使用字符串缓冲区作为第一个
参数,则此方法可以正常工作。

看起来标准描述符并非真正打开。



''file''不是标准流的名称。


Randy Yates写道:

当我尝试使用

fprintf(文件,报告文件%s \ n,sMF-> fileName);

我得到一个核心倾倒。如果将fprintf更改为sprintf并使用字符串缓冲区作为第一个
参数,则此方法可以正常工作。

看起来标准描述符并非真正打开。



`file''不是标准描述符;你需要为自己付出
fopen()吧。请注意,fopen()可能会失败,所以

必须先检查返回值是否为NULL,然后再将
交给fprintf()。


另一种可能性是你fopen()ed`file''

成功但后来fclose()d;如果你然后通过

它到fprintf()所有的赌注都关闭了。


第三种(可能不太可能)的可能性是

`file''是fopen()ed成功并且仍然打开,

但你在它上面使用了setvbuf()并给它一个缓冲区

区域是从来没有或不再有效,或者比你说的要小b



第四种可能性是'sMF-> fileName''是什么造成了麻烦:你确定它是非NULL,

并且它实际上指的是零开始 -

终止字符串?您使用sprintf()进行的实验似乎是建议如此,但您究竟是如何确定实验正常工作的?



-
Er*********@sun.com


Eric Sosman< er ********* @ sun.com>写道:

Randy Yates写道:

当我尝试
fprintf(文件,报告文件%s \ n,sMF) - > fileName);

我得到一个核心转储。如果将fprintf更改为


sprintf并使用字符串缓冲区作为第一个
参数,则此方法可以正常工作。
它看起来像标准描述符是不是真正开放。



`file''不是标准描述符;你需要为自己fopen()它。请注意,fopen()可能会失败,所以你必须在将它返回到fprintf()之前检查返回值是否为NULL。




I对不起 - 这个片段有误导性。它是

子程序的一部分,文件作为传递参数,我将b参数设置为stdout。在调用

例程中。

另一种可能性是你fopen()ed`file''
成功,但后来fclose()d;如果你然后将它传递给fprintf(),那么所有的赌注都会被取消。


你的意思是我fclose()d" stdout"?不,我不认为我已经完成了这个。

第三种(可能不太可能)的可能性是
`file''是fopen( )ed成功并且仍处于打开状态,但是你在它上面使用了setvbuf()并给它一个缓冲区域,它从未或不再有效,或者比你说的要小它是。

第四种可能性是'sMF-> fileName''是什么导致了麻烦:你确定它是非NULL,
它实际上指向一个零终止字符串的开头?您对sprintf()的实验似乎建议如此,但您究竟如何确定实验是否正常?




好​​的,我改变了测试。当我打电话给SMFReport时,

前几行是:


void SMFReport(FILE * file,SMF_T * sMF)

$

UINT16_T n;

浮动文件;

BOOL_T仍然在玩;


printf( 这里是0 \ n;;

fprintf(stdout,SMF Report of file \ n);

// fprintf(stdout,"文件%s \ n",sMF-> fileName)的SMF报告;


printf(" here 1 \ n");


When I try

fprintf(file, "Report of File %s\n", sMF->fileName);

I get a core dump. This works fine if fprintf is changed to
sprintf and a string buffer used instead as the first
parameter.

It looks like the standard descriptors are not really open.

This is Sun/Solaris

SunOS usrts005 5.8 Generic_117350-08 sun4u sparc SUNW,Ultra-5_10

using gcc

Reading specs from /vobs/edgedsp_tools/solaris/lib/gcc-lib/sparc-sun-solaris2.7/3.0.4/specs
Configured with: ../../gcc-3.0.4/configure --prefix=/vobs/edgedsp_tools/solaris
Thread model: posix
gcc version 3.0.4
--
Randy Yates
Sony Ericsson Mobile Communications
Research Triangle Park, NC, USA
ra*********@sonyericsson.com, 919-472-1124

解决方案

Randy Yates wrote:

When I try

fprintf(file, "Report of File %s\n", sMF->fileName);

I get a core dump. This works fine if fprintf is changed to
sprintf and a string buffer used instead as the first
parameter.

It looks like the standard descriptors are not really open.



''file'' is not the name of a standard stream.


Randy Yates wrote:

When I try

fprintf(file, "Report of File %s\n", sMF->fileName);

I get a core dump. This works fine if fprintf is changed to
sprintf and a string buffer used instead as the first
parameter.

It looks like the standard descriptors are not really open.



`file'' is not a "standard descriptor;" you need to
fopen() it for yourself. Note that fopen() can fail, so
you must check the returned value against NULL before
handing it to fprintf().

Another possibility is that you fopen()ed `file''
successfully but later fclose()d it; if you then pass
it to fprintf() all bets are off.

A third (perhaps less likely) possibility is that
`file'' was fopen()ed successfully and is still open,
but that you used setvbuf() on it and gave it a buffer
area that was never or is no longer valid, or is
smaller than you said it was.

And a fourth possibility is that `sMF->fileName'' is
what''s causing the trouble: are you sure it''s non-NULL,
and that it actually points to the start of a zero-
terminated string? Your experiment with sprintf() would
seem to suggest so, but how exactly did you determine
that the experiment worked correctly?

--
Er*********@sun.com


Eric Sosman <er*********@sun.com> writes:

Randy Yates wrote:

When I try
fprintf(file, "Report of File %s\n", sMF->fileName);

I get a core dump. This works fine if fprintf is changed to


sprintf and a string buffer used instead as the first
parameter.
It looks like the standard descriptors are not really open.


`file'' is not a "standard descriptor;" you need to
fopen() it for yourself. Note that fopen() can fail, so
you must check the returned value against NULL before
handing it to fprintf().



I''m sorry - that snippet was misleading. It is part of
a subroutine with file as a passed parameter, and I
am setting the parameter to "stdout" in the calling
routine.
Another possibility is that you fopen()ed `file''
successfully but later fclose()d it; if you then pass
it to fprintf() all bets are off.
You mean I fclose()d "stdout"? No, I don''t think I have
done that.
A third (perhaps less likely) possibility is that
`file'' was fopen()ed successfully and is still open,
but that you used setvbuf() on it and gave it a buffer
area that was never or is no longer valid, or is
smaller than you said it was.

And a fourth possibility is that `sMF->fileName'' is
what''s causing the trouble: are you sure it''s non-NULL,
and that it actually points to the start of a zero-
terminated string? Your experiment with sprintf() would
seem to suggest so, but how exactly did you determine
that the experiment worked correctly?



OK, I''ve changed the test. When I call SMFReport, the
first few lines of which are:

void SMFReport(FILE* file, SMF_T* sMF)
{
UINT16_T n;
float fileUs;
BOOL_T stillKicking;

printf("here 0\n");
fprintf(stdout, "SMF Report of File \n");
// fprintf(stdout, "SMF Report of File %s\n", sMF->fileName);

printf("here 1\n");


这篇关于stdout没开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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