linux c文件操作,linux c 下的文件操作

在linux c 下是否能够使用fopen 和fclose 两个函数打开文件?为什么我使用fopen是程序出现“core dump”的错误,而使用open却可以成功。因为我接下来的工作用fopen比较方便,所以请高手指教。

还有是不是所有vc下的c函数都能够在linux c下使用?

|

C语言在Linux下面是完全可以用这两个函数的,可能是没有连接好函数库!

|

肯定可以,标准C的。

关键是你代码其他地方有错误操作。

|

study

|

描述符 定义错了吧?

|

fopen 需要返回一个FILE*类型,而open是返回一个int类型,楼主应该是文件描述符定义的类型不对。如果用int类型去获取fopen的返回应该就会出错。

|

如果是内核方面的开发不能使用标准C库文件,

如果是作应用,要确定fopen()函数的返回值

|

linux下当然可以使用fopen和fclose,你出错的程序贴上来看看?

|

1. 确认是 fopen就错了,还是之后,比如open一个不存在的文件,然后fread就会错

2. 确认是否是应用程序,在驱动里不能用fopen

|

linux c 下是能够使用fopen 和fclose 两个函数打开文件, 出现错误, 查一下参数有没有对.

还有是不是所有vc下的c函数都能够在linux c下使用?

ANSI C 的库函数都能够在 Linux下使用.

|

#include

FILE *fopen(const char *path, const char *mode);

The argument mode points to a string beginning with one of the following sequences (Additional  characters  may follow these sequences.):

r      Open text file for reading.  The stream is positioned at the beginning of the file.

r+     Open for reading and writing.  The stream is positioned at the beginning of the file.

w      Truncate file to zero length or create text file for writing.  The stream is positioned at the beginning of the file.

w+     Open for reading and writing.  The file is created if it does not exist, otherwise it is truncated.  The stream is positioned at the beginning of the file.

a      Open  for  appending (writing at end of file).  The file is created if it does not exist.  The stream is positioned at the end of the file.

a+     Open for reading and appending (writing at end of file).  The file is created if it does not exist.  The initial  file position for reading is at the beginning of the file, but output is always appended to the end of the file.

|

仔细比对,是不是自己函数某个参数错了。导致这个问题的情况很多。把代码贴上来,大家共赏。

|

fopen和open最主要的区别是fopen在用户态下就有了缓存,在进行read和write的时候减少了用户态和内核态的切换,而open则每次都需要进行内核态和用户态的切换;表现为,如果顺序访问文件,fopen系列的函数要比直接调用open系列快;如果随机访问文件open要比fopen快。

|

还是建议和程序贴出来看看!

|

理论上都可以的,你还是上代码吧!

尽管在linux里面所有的设备都可以当做一个文件来看待,不过使用习惯上还是有些差别

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值