FWRITE [英] fwrite

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

问题描述

如果我有

typedef struct {

unsigned a;

unsigned * b;

} tp ;


i想询问C标准89是否合适。做

这样的事情


{

unsigned val = 1;

tp e;

size_t k;

FILE fp;


ea = 1; eb =& val;


if((pf = fopen(" file.dat"," w"))== 0)return 0;


k = fwrite(& e,sizeof(unsigned),1,fp);

if(k <1){fclose(fp);返回0;}

fwrite(e.b,sizeof(unsigned),e.a,fp);

if(k< e.a){fclose(fp);返回0;}


如果在> 98%cpu-oses中它可以正常,我也会问。谢谢

if i have
typedef struct{
unsigned a;
unsigned *b;
}tp;

i would like to ask if it is ok for the "C standard 89" doing
something like this

{
unsigned val=1;
tp e;
size_t k;
FILE fp;

e.a=1; e.b=&val;

if( (pf=fopen("file.dat", "w")) == 0 ) return 0;

k=fwrite(&e, sizeof(unsigned), 1, fp);
if(k<1) {fclose(fp); return 0;}
fwrite(e.b, sizeof(unsigned), e.a, fp);
if(k<e.a) {fclose(fp); return 0;}

I would ask too if it goes ok in >98% cpu-oses. Thank you

推荐答案

cs写道:
如果我有
typedef struct {
unsigned a ;
未签名* b;
} tp;

我想问一下C标准89是否可以。做这样的事情

{
无符号val = 1;
tp e;
size_t k;
FILE fp;


请提供可以编译的代码 - 我不知道是否

你犯的错误(FILE而不是FILE *,pf / fp等)是只是

因为你懒得提供一个编译的最小例子

和_paste_它没有改变或因为你至少不知道
意识到你正在做什么。


当你试图通过伪代码向我们展示你的问题时,它应该明确问题是什么。 br /> ea = 1; e.b =& val;

if((pf = fopen(" file.dat"," w"))== 0)return 0;


这里你的程序出错了。
k = fwrite(& e,sizeof(unsigned),1,fp);


注意:

k = fwrite(& e.a,sizeof e.a,1,fp);

更安全;如果你改变ea的类型,输出将自动正确。

是的,ea和e的地址相同。

if(k <1){fclose(fp);返回0;}
fwrite(e.b,sizeof(unsigned),e.a,fp);


你忘了分配给k。

k = fwrite(eb,sizeof * eb,ea,fp);

一次越多越好。

if(k
我也会问,如果它在> 98%cpu-oses中没问题。谢谢
if i have
typedef struct{
unsigned a;
unsigned *b;
}tp;

i would like to ask if it is ok for the "C standard 89" doing
something like this

{
unsigned val=1;
tp e;
size_t k;
FILE fp;
Please provide code which can compile -- I do not know whether
the mistakes you make (FILE instead of FILE*, pf/fp etc) are just
because you were to lazy to provide a compiling minimal example
and _paste_ it unchanged or because you are not in the least
aware of what you are doing.

As you are trying to show us your question by pseudo-code, it
should be made clear what the question is.
e.a=1; e.b=&val;

if( (pf=fopen("file.dat", "w")) == 0 ) return 0;
Here your program goes wrong.
k=fwrite(&e, sizeof(unsigned), 1, fp);
Note:
k = fwrite(&e.a, sizeof e.a, 1, fp);
is much safer; if you change the type of e.a, the output will
automatically be correct.
And yes, e.a has the same address as e.
if(k<1) {fclose(fp); return 0;}
fwrite(e.b, sizeof(unsigned), e.a, fp);
You forgot to assign to k.
k = fwrite(e.b, sizeof *e.b, e.a, fp);
once more is better.
if(k<e.a) {fclose(fp); return 0;}

I would ask too if it goes ok in >98% cpu-oses. Thank you




什么是cpu-ose?我在哪里可以找到你喜欢的C标准?

你的实际问题是什么?

离开main()和关闭括号等在任何地方都无效。

如果您从所有这些程序编制程序,那就再来一次。


这次没有使用水晶球的费用。

干杯

Michael

-

电子邮件:我的是/ at / gmx / dot / de地址。



What''s a cpu-ose? Where can I find it in a C standard of your liking?
What was your actual question?
Leaving out main() and closing braces etc. will not work anywhere.
If you make a compiling program from all of it, then come again.

This time no fees for crystal ball use.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.


2005年7月16日星期六06:58:28 GMT,cs< n@ss.g>写道:
On Sat, 16 Jul 2005 06:58:28 GMT, cs <n@ss.g> wrote:
如果我有
typedef struct {
unsigned a;
unsigned * b;
} tp;

我想问一下C标准89是否合适。
这样的事情

{
无符号val = 1;
tp e;
size_t k;
FILE fp;

ea = 1; eb =& val;

if((pf = fopen(" file.dat"," w"))== 0)返回0;

k = fwrite(& e,sizeof(unsigned),1,fp);
if(k <1){fclose(fp);返回0;}
fwrite(eb,sizeof(unsigned),ea,fp);
if i have
typedef struct{
unsigned a;
unsigned *b;
}tp;

i would like to ask if it is ok for the "C standard 89" doing
something like this

{
unsigned val=1;
tp e;
size_t k;
FILE fp;

e.a=1; e.b=&val;

if( (pf=fopen("file.dat", "w")) == 0 ) return 0;

k=fwrite(&e, sizeof(unsigned), 1, fp);
if(k<1) {fclose(fp); return 0;}
fwrite(e.b, sizeof(unsigned), e.a, fp);



k = fwrite(eb,sizeof(unsigned),ea,fp);


写好

k = fwrite(&(ea),sizeof(unsigned),1,fp);

insteaf

k = fwrite(& e,sizeof(unsigned),1,fp);?

谢谢


k=fwrite(e.b, sizeof(unsigned), e.a, fp);

it is good to write
k=fwrite(&(e.a), sizeof(unsigned), 1, fp);
insteaf of
k=fwrite(&e, sizeof(unsigned), 1, fp);?
Thank you


Michael Mair写道:
Michael Mair wrote:
cs写道:

我也会问,如果它在> 98%cpu-中没问题操作系统。谢谢

I would ask too if it goes ok in >98% cpu-oses. Thank you



什么是cpu-ose?



What''s a cpu-ose?




它是标准输入流的来源。它的目的是帮助

机器保持所有点数。

-

Richard Heathfield

" ; Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

邮件:rjh在上述域名



It''s the source for the standard input stream. Its purpose is to help the
machine keep all the points afloat.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain


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

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