文件编程

Linux系统调用方式访问文件

create(const char* filename,mode_t mode);
mode: S_IRUSR , S_IWUSR , S_IXUSR  , S_IRWXU


int open(const char* pathname,int flags);
int open(const char* pathname,int flags,mode_t mode);
打开方式flags:O_RDONLY,O_WRONLY,O_RDWR,O_APPEND,O_CREATE(文件不存在时,创建之),O_NOLOCK

int close(int fd);

int read(int fd,const void* buf,size_t length);

int lseek(int fd,offset_t offset,int whence);
whence: SEEK_SET,SEEK_CUR,SEEK_END

int access(const char* pathname,int mode);
mode: R_OK,W_OK,X_OK,F_OK

 


库函数访问文件

FILE* fopen(const char* filename,const char* mode);
打开模式:r,rb;w,wb;a,ab;r+,r+b,rb+;w+,w+b,wh+;a+,a+b,ab+

size_t fread(void* ptr,size_t size,size_t n,FILE* stream);
size_t fwrite(const void* ptr,size_t size,size_t n,FILE* stream);

int fgetc(FILE* stream);

int fputc(int c,FILE* stream);

fscanf(FILE* stream,char* format[,argument...]);
fprintf(FILE* stream,char* format[,argument...]);

int fseek(FILE* stream,long offset,int whence);
whence: SEEK_SET,SEEK_CUR,SEEK_END

char* getcwd(char *buffer,size_t size);


时间编程:

#include <time.h>
time_t time(time_t* tloc);获取日历时间,即从1970年1月1日0点到现在的秒数。

struct tm*gmtime(const time_t* timep);将日历时间转化为格林威治标准时间。

struct tm* localtime(const time_t* timep);将日历时间转化为本地时间

int gettimeofday(struct timeval* tv,struct timezone *tz)

struct tm{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
}

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值