百科问答小站 logo
百科问答小站 font logo



这个如此诡异的C语言「怪事」是怎么回事? 第1页

  

user avatar   bei-ji-85 网友的相关建议: 
      

把fopen的参数从"w"换成"wb",你要写字节流,就要以二进制方式访问。

以文本模式的话,就会给你转换。

原因的话,看这里:


In text mode, CTRL+Z is interpreted as an EOF character on input. In files that are opened for reading/writing by using "a+", fopen checks for a CTRL+Z at the end of the file and removes it, if it is possible. This is done because using fseek and ftell to move within a file that ends with CTRL+Z may cause fseek to behave incorrectly near the end of the file.
In text mode, carriage return-line feed combinations are translated into single line feeds on input, and line feed characters are translated to carriage return-line feed 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).
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.


注意整句加粗的那个。这不是错误,这是你没了解fopen这个函数的参数含义。


user avatar   pansz 网友的相关建议: 
      

毫无问题。

牛顿最大的成就不是物理学成就,而是数学成就,这是发明了微积分的牛人。

弄懂相对论跟量子力学,其实对普通人来说,最大的困难依然不是物理上的理解困难,而是数学能力。只要数学能力足够,理解相对论跟量子力学并没有那么大的困难。

牛顿,作为一个伟大的数学家,看这些并不会有困难,拿到物理学博士显然也没有问题。

--

可能唯一的问题就是:他最好能活得足够久不要英年早逝,毕竟现代的病毒比他当年要厉害多了。




  

相关话题

  为什么看到这么多人不推荐C++? 
  大一新生做C语言课设被强制要求使用 Borland C++ 3.1,此IDE相对于其他IDE有何优点? 
  刚上大一,C 语言压根听不懂怎么办? 
  为什么说 goto 是一种不好的用法? 
  怎样用c语言画一个"三维的球体"? 
  Objective-C 的一些函数名为什么都这么长? 
  为什么C++头文件喜欢把一个类型通过typedef定义出无数个新名字,这有什么意义吗? 
  该如何正确看待c中的字符串常量? 
  现在快2022年了,c++为什么还要实现(.cpp)和声明(.h)分开? 
  C++ 中,如果指针换了被指向的东西,那被指向的原来的东西(是被 new 出来的)所占的内存会立刻被释放吗? 

前一个讨论
如何看待英特尔(intel)CPU机密数据泄露?
下一个讨论
公历1582年消失了10天,但我国的农历用了这么多年,难道没有误差吗?





© 2025-04-16 - tinynew.org. All Rights Reserved.
© 2025-04-16 - tinynew.org. 保留所有权利