C中的fwrite [英] fwrite in C

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

问题描述

你好,

我一直试图用fwrite()构建一个程序,它只是在一个名为Project.doc的文件中写入一个包含10个整数的数组。这是代码:

Hello,
I''ve been trying to build a program with fwrite( ), that just writes an array of 10 integers at a file called Project.doc. Here is the code:

展开 | 选择 | Wrap | 行号

推荐答案

考虑数字1和字符常量''1''。这些是完全不同的东西,具有不同的值。


考虑数字10.这个数字存在于一个变量中。但是,要打印出来,您需要打印1后跟0 - 两个字符代表一个数字。你混淆了一个数字的值和你打印的字符来代表数字。


char a [10] = {1,2,3,4,5,6,7 ,8,9,10};

虽然类型是''char'',但这些数字不是字符。
Consider the difference between the number 1 and the character constant ''1''. These are quite different things, with different values.

Consider the number 10. This number resides in a single variable. However, to print it out you need to print ''1'' followed by ''0'' -- two characters to represent a single number. You are confusing the value of a number and the characters you print to represent the number.

char a[10]={1,2,3,4,5,6,7,8,9,10};
Although the type is ''char'', these are numbers not characters.


所以这意味着fwrite()仅适用于角色?你能更具体一点吗?我需要做什么才能在.txt文件中写入那10个整数?我使用了错误的功能吗?


Thanx,

Alex
So this means that fwrite( ) is only for characters? Could you be a little more specific? What do I have to do so that I write in a .txt file those 10 integers? Am I using the wrong functions?

Thanx,
Alex


不,他在说你是什么在你的数组中不是chars。您需要更改它,以便使用单引号使用1,2,3,以便编译器知道这些是您想要的字符。
No, he''s saying what you have in your array is not chars. You need to change that so you have ''1'',''2'',''3'' with the single quotes so the compiler knows these are the chars you want.


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

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