[英]How do you write the same bytes twice in C?
short i = 1;
fwrite(&i, sizeof(i), 1, file);
fwrite(&i, sizeof(i), 1, file);
Is that proper? 那合适吗? I want to write the same i
twice. 我想写同i
的两倍。
There's nothing wrong with it; 这没什么不对的。 just remember to check the return value. 只要记得检查返回值即可。
Yes, that will work fine. 是的,那会很好。 Alternatively you could declare an array of two and use a single fwrite
, which would theoretically be more efficient: 或者,您可以声明一个由2组成的数组,并使用一个fwrite
,从理论上讲,这将更有效:
short i[2] = {1, 1};
fwrite(i, sizeof(short), 2, file);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.