fwrite问题,无法写入二进制文件!
可能的重复:
C 编程 - 文件 - fwrite
包括... >
int main(void)
{
FILE *Archivo;
int proba=5;
Archivo=fopen("md3.dat", "ab+");
fwrite(&proba, sizeof(int), 1, Archivo);
fclose(Archivo);
printf("Bye!\n\n");
}
我只是无法在二进制 fila md3.dat 上打印任何数字,请帮忙!
Possible Duplicate:
C Programming - File - fwrite
include....
>
int main(void)
{
FILE *Archivo;
int proba=5;
Archivo=fopen("md3.dat", "ab+");
fwrite(&proba, sizeof(int), 1, Archivo);
fclose(Archivo);
printf("Bye!\n\n");
}
I just can't print any number on the binary fila md3.dat, please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为OP期望
fwrite
表现得像fprintf
并在文件中写入一个ASCII十进制字符串,然后当输出是字节5,0时感到困惑, 0,0
(所有不可打印的字符),在编辑器中打开它或使用cat
将其打印到终端(或type
> 在 DOS 上)。如果您想写入文本,请使用
fprintf
。I think OP is expecting
fwrite
to behave asfprintf
and write an ASCII decimal string the the file, then getting confused when the output is the bytes5,0,0,0
(all non-printable characters) which probably shows up blank when opening it in an editor or usingcat
to print it to the terminal (ortype
on DOS).If you want to write text, use
fprintf
.试试这个:
这应该在文件末尾写入您的
int
值。另外,您应该检查函数返回值。请记住:你在 C 语言!!。Try this:
This should write your
int
value at the end of the file. Also, you should check for function return values. Remember: you are in C!!.