c语言文件的输入输出---乱码

Gnglas 2019-10-08 02:03:26
由于电脑不在身边直接上图
...全文
229 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
Gnglas 2019-10-10
  • 打赏
  • 举报
回复
引用 16 楼 赵4老师 的回复:
以为用VS2019,MSDN98就没用的人,充分暴露了自己是Windows软件开发门外汉。
大哥我才刚刚自学完c,现在还只是在复习阶段
赵4老师 2019-10-10
  • 打赏
  • 举报
回复
以为用VS2019,MSDN98就没用的人,充分暴露了自己是Windows软件开发门外汉。
Gnglas 2019-10-10
  • 打赏
  • 举报
回复
引用 14 楼 赵4老师的回复:
[quote=引用 13 楼 Gnglas 的回复:] [quote=引用 11 楼 赵4老师的回复:]MSDN98_1.ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2.ISO http://pan.baidu.com/s/1bnGo0Vl
这个是什么啊000000000[/quote] 大名鼎鼎的和VC6配套的离线MSDN[/quote] 我用的vs2019。。。。。
Gnglas 2019-10-09
  • 打赏
  • 举报
回复
引用 9 楼 赵4老师 的回复:
你不会全选,复制,粘贴到百度翻译(fanyi.baidu.com)翻译一下啊?
字符串模式指定为文件请求的访问类型,如下所示:



“R”



打开阅读。如果文件不存在或找不到,则FPEN调用失败。



“W”



打开一个空文件进行写入。如果给定文件存在,则其内容被销毁。



“一”



在文件结束之前打开文件(追加),而不必在写入新数据之前删除EOF标记;如果文件不存在,则首先创建文件。



“R+”



为阅读和写作打开。(文件必须存在。)



“W+”



打开一个空文件进行读写。如果给定文件存在,则其内容被销毁。



“A+”



打开读取和追加;追加操作包括在新数据写入文件之前移除EOF标记,在写入完成后恢复EOF标记;如果不存在,则首先创建文件。



当使用“A”或“A+”访问类型打开文件时,所有写操作都会在文件末尾进行。可以使用fseek或rewind重新定位文件指针,但在执行任何写操作之前,总是将其移回文件末尾。因此,无法重写现有数据。



“A”模式在附加到文件之前不会删除EOF标记。追加后,ms-dos type命令只显示原始eof标记之前的数据,而不显示追加到文件的任何数据。“A+”模式在附加到文件之前会删除EOF标记。追加后,ms-dos type命令显示文件中的所有数据。附加到用ctrl+z eof标记终止的流文件时需要使用“a+”模式。



如果指定了“r+”、“w+”或“a+”访问类型,则允许读取和写入(文件被称为打开以进行“更新”)。但是,当您在读和写之间切换时,必须有一个中间的fflush、fsetpos、fseek或rewind操作。如果需要,可以为fsetpos或fseek操作指定当前位置。



除上述值外,模式中还可以包含以下字符,以指定换行字符的转换模式:



T



以文本(翻译)模式打开。在这种模式下,ctrl+z在输入时被解释为文件结束字符。在用“a+”打开进行读/写的文件中,fopen会检查文件末尾是否有ctrl+z,并在可能的情况下将其删除。之所以这样做,是因为使用fseek和ftell在以ctrl+z结尾的文件中移动,可能会导致fseek在文件结尾附近的行为不正常。



此外,在文本模式下,回车换行组合在输入时转换为单行换行,换行字符在输出时转换为回车换行组合。当unicode stream-i/o函数以文本模式(默认)运行时,源或目标流被假定为多字节字符序列。因此,unicode流输入函数将多字节字符转换为宽字符(就像通过调用mbtowc函数一样)。出于同样的原因,unicode流输出函数将宽字符转换为多字节字符(就像通过调用wctomb函数一样)。







以二进制(未翻译)模式打开;涉及回车和换行字符的翻译被禁止。



如果T或B未在模式中给定,则默认转换模式由全局变量_fmode定义。如果参数的前缀是t或b,则函数将失败并返回null。



有关在Unicode和多字节流I/O中使用文本和二进制模式的详细信息,请参阅文本和二进制模式下的文本和二进制模式文件I/O和Unicode流I/O。



C类



为关联的文件名启用commit标志,以便在调用fflush或flushall时将文件缓冲区的内容直接写入磁盘。



n个



将关联文件名的提交标志重置为“无提交”。这是默认值。如果您将程序链接到commode.obj,它还会覆盖全局提交标志。除非您显式地将程序与commode.obj链接,否则全局提交标志默认为“no commit”。
真不知道大佬从哪扒出来的,不过还是谢谢了
赵4老师 2019-10-09
  • 打赏
  • 举报
回复
你不会全选,复制,粘贴到百度翻译(fanyi.baidu.com)翻译一下啊? 字符串模式指定为文件请求的访问类型,如下所示: “R” 打开阅读。如果文件不存在或找不到,则FPEN调用失败。 “W” 打开一个空文件进行写入。如果给定文件存在,则其内容被销毁。 “一” 在文件结束之前打开文件(追加),而不必在写入新数据之前删除EOF标记;如果文件不存在,则首先创建文件。 “R+” 为阅读和写作打开。(文件必须存在。) “W+” 打开一个空文件进行读写。如果给定文件存在,则其内容被销毁。 “A+” 打开读取和追加;追加操作包括在新数据写入文件之前移除EOF标记,在写入完成后恢复EOF标记;如果不存在,则首先创建文件。 当使用“A”或“A+”访问类型打开文件时,所有写操作都会在文件末尾进行。可以使用fseek或rewind重新定位文件指针,但在执行任何写操作之前,总是将其移回文件末尾。因此,无法重写现有数据。 “A”模式在附加到文件之前不会删除EOF标记。追加后,ms-dos type命令只显示原始eof标记之前的数据,而不显示追加到文件的任何数据。“A+”模式在附加到文件之前会删除EOF标记。追加后,ms-dos type命令显示文件中的所有数据。附加到用ctrl+z eof标记终止的流文件时需要使用“a+”模式。 如果指定了“r+”、“w+”或“a+”访问类型,则允许读取和写入(文件被称为打开以进行“更新”)。但是,当您在读和写之间切换时,必须有一个中间的fflush、fsetpos、fseek或rewind操作。如果需要,可以为fsetpos或fseek操作指定当前位置。 除上述值外,模式中还可以包含以下字符,以指定换行字符的转换模式: T 以文本(翻译)模式打开。在这种模式下,ctrl+z在输入时被解释为文件结束字符。在用“a+”打开进行读/写的文件中,fopen会检查文件末尾是否有ctrl+z,并在可能的情况下将其删除。之所以这样做,是因为使用fseek和ftell在以ctrl+z结尾的文件中移动,可能会导致fseek在文件结尾附近的行为不正常。 此外,在文本模式下,回车换行组合在输入时转换为单行换行,换行字符在输出时转换为回车换行组合。当unicode stream-i/o函数以文本模式(默认)运行时,源或目标流被假定为多字节字符序列。因此,unicode流输入函数将多字节字符转换为宽字符(就像通过调用mbtowc函数一样)。出于同样的原因,unicode流输出函数将宽字符转换为多字节字符(就像通过调用wctomb函数一样)。 乙 以二进制(未翻译)模式打开;涉及回车和换行字符的翻译被禁止。 如果T或B未在模式中给定,则默认转换模式由全局变量_fmode定义。如果参数的前缀是t或b,则函数将失败并返回null。 有关在Unicode和多字节流I/O中使用文本和二进制模式的详细信息,请参阅文本和二进制模式下的文本和二进制模式文件I/O和Unicode流I/O。 C类 为关联的文件名启用commit标志,以便在调用fflush或flushall时将文件缓冲区的内容直接写入磁盘。 n个 将关联文件名的提交标志重置为“无提交”。这是默认值。如果您将程序链接到commode.obj,它还会覆盖全局提交标志。除非您显式地将程序与commode.obj链接,否则全局提交标志默认为“no commit”。
Gnglas 2019-10-09
  • 打赏
  • 举报
回复
引用 7 楼 赵4老师的回复:
The character string mode specifies the type of access requested for the file, as follows: "r" Opens for reading. If the file does not exist or cannot be found, the fopen call fails. "w" Opens an empty file for writing. If the given file exists, its contents are destroyed. "a" Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn’t exist. "r+" Opens for both reading and writing. (The file must exist.) "w+" Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed. "a+" Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn’t exist. When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten. The "a" mode does not remove the EOF marker before appending to the file. After appending has occurred, the MS-DOS TYPE command only shows data up to the original EOF marker and not any data appended to the file. The "a+" mode does remove the EOF marker before appending to the file. After appending, the MS-DOS TYPE command shows all data in the file. The "a+" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker. When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for “update”). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired. In addition to the above values, the following characters can be included in mode to specify the translation mode for newline characters: t Open in text (translated) mode. In this mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing with "a+", fopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z, may cause fseek to behave improperly near the end of the file. Also, in text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function). b Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed. If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL. For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes. c Enable the commit flag for the associated filename so that the contents of the file buffer are written directly to disk if either fflush or _flushall is called. n Reset the commit flag for the associated filename to “no-commit.” This is the default. It also overrides the global commit flag if you link your program with COMMODE.OBJ. The global commit flag default is “no-commit” unless you explicitly link your program with COMMODE.OBJ.
完全看不懂啊 。
赵4老师 2019-10-09
  • 打赏
  • 举报
回复
引用 13 楼 Gnglas 的回复:
[quote=引用 11 楼 赵4老师的回复:]MSDN98_1.ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2.ISO http://pan.baidu.com/s/1bnGo0Vl
这个是什么啊000000000[/quote] 大名鼎鼎的和VC6配套的离线MSDN
Gnglas 2019-10-09
  • 打赏
  • 举报
回复
引用 11 楼 赵4老师的回复:
MSDN98_1.ISO http://pan.baidu.com/s/1dDF41ix, MSDN98_2.ISO http://pan.baidu.com/s/1bnGo0Vl
这个是什么啊000000000
赵4老师 2019-10-09
  • 打赏
  • 举报
回复
你不会全选,复制,粘贴到百度翻译(fanyi.baidu.com)翻译一下啊?
赵4老师 2019-10-09
  • 打赏
  • 举报
回复
赵4老师 2019-10-08
  • 打赏
  • 举报
回复
The character string mode specifies the type of access requested for the file, as follows: "r" Opens for reading. If the file does not exist or cannot be found, the fopen call fails. "w" Opens an empty file for writing. If the given file exists, its contents are destroyed. "a" Opens for writing at the end of the file (appending) without removing the EOF marker before writing new data to the file; creates the file first if it doesn’t exist. "r+" Opens for both reading and writing. (The file must exist.) "w+" Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed. "a+" Opens for reading and appending; the appending operation includes the removal of the EOF marker before new data is written to the file and the EOF marker is restored after writing is complete; creates the file first if it doesn’t exist. When a file is opened with the "a" or "a+" access type, all write operations occur at the end of the file. The file pointer can be repositioned using fseek or rewind, but is always moved back to the end of the file before any write operation is carried out. Thus, existing data cannot be overwritten. The "a" mode does not remove the EOF marker before appending to the file. After appending has occurred, the MS-DOS TYPE command only shows data up to the original EOF marker and not any data appended to the file. The "a+" mode does remove the EOF marker before appending to the file. After appending, the MS-DOS TYPE command shows all data in the file. The "a+" mode is required for appending to a stream file that is terminated with the CTRL+Z EOF marker. When the "r+", "w+", or "a+" access type is specified, both reading and writing are allowed (the file is said to be open for “update”). However, when you switch between reading and writing, there must be an intervening fflush, fsetpos, fseek, or rewind operation. The current position can be specified for the fsetpos or fseek operation, if desired. In addition to the above values, the following characters can be included in mode to specify the translation mode for newline characters: t Open in text (translated) mode. In this mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing with "a+", fopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z, may cause fseek to behave improperly near the end of the file. Also, in text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters (as if by a call to the mbtowc function). For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters (as if by a call to the wctomb function). b Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed. If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL. For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes. c Enable the commit flag for the associated filename so that the contents of the file buffer are written directly to disk if either fflush or _flushall is called. n Reset the commit flag for the associated filename to “no-commit.” This is the default. It also overrides the global commit flag if you link your program with COMMODE.OBJ. The global commit flag default is “no-commit” unless you explicitly link your program with COMMODE.OBJ.
Gnglas 2019-10-08
  • 打赏
  • 举报
回复
我也不记得了,今天刚学
铖邑 2019-10-08
  • 打赏
  • 举报
回复
引用 4 楼 Gnglas 的回复:
[quote=引用 1 楼 SuperDay的回复:]打开读写文件应该是rw
wt+ ,[/quote]哦,忘记了
Gnglas 2019-10-08
  • 打赏
  • 举报
回复
引用 1 楼 SuperDay的回复:
打开读写文件应该是rw
wt+ ,
Gnglas 2019-10-08
  • 打赏
  • 举报
回复
引用 2 楼 自信男孩的回复:
在读文件之前,先把fp更新一下,因为上面的写文件已经把fp指向了文件末尾,所以,你读取的时候要从文件开头读取。rewind(fp);加一下这句,在读取之前。

另外,EOF是-1是int类型,因此ch,定义为int类型。

把这两个地方改一下试试~
大佬好久不见了,感谢
自信男孩 2019-10-08
  • 打赏
  • 举报
回复
在读文件之前,先把fp更新一下,因为上面的写文件已经把fp指向了文件末尾,所以,你读取的时候要从文件开头读取。rewind(fp);加一下这句,在读取之前。

另外,EOF是-1是int类型,因此ch,定义为int类型。

把这两个地方改一下试试~
铖邑 2019-10-08
  • 打赏
  • 举报
回复
打开读写文件应该是rw

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧