当前位置: 技术问答>linux和unix
怎样把两个整数写入一个文件再读出来?
来源: 互联网 发布时间:2015-05-19
本文导语: # include # include # include # include # include # include # include # include # include # include # include "ourhdr.h" # include char *filepath="./fortest"; int fd; int buff[2]; void showerr(char *errinfo) { printf("%s",errin...
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include "ourhdr.h"
# include
char *filepath="./fortest";
int fd;
int buff[2];
void
showerr(char *errinfo)
{
printf("%s",errinfo);
exit(0);
}
int
main(void)
{
srandom(time(NULL)); //设置随机种子
buff[0]=random()%100; //产生随机数
buff[1]=getpid(); //获取进程id
if((fd=open(filepath,O_RDWR|O_TRUNC|O_CREAT,S_IRWXU|S_IRWXG|S_IRWXO))
# include
# include
# include
# include
# include
# include
# include
# include
# include
# include "ourhdr.h"
# include
char *filepath="./fortest";
int fd;
int buff[2];
void
showerr(char *errinfo)
{
printf("%s",errinfo);
exit(0);
}
int
main(void)
{
srandom(time(NULL)); //设置随机种子
buff[0]=random()%100; //产生随机数
buff[1]=getpid(); //获取进程id
if((fd=open(filepath,O_RDWR|O_TRUNC|O_CREAT,S_IRWXU|S_IRWXG|S_IRWXO))