使用write函数来编写一个程序,在程序中指定一个文件,用户可以向程序中一次写入不超过80个字符的数

发布时间:2020-07-04 07:20:10 作者:银河星君
来源:网络 阅读:574

/*

#define FLAGS O_RDWR|O_APPEND
#define SIZE 80
#define FILENAME "/home/mrhe/hello"

int main(int argc, char argv[])
{
int count;
int fd;
char write_buf[SIZE];
const char
pathname=FILENAME;
if((fd=open(pathname,FLAGS))==-1)//调用open函数打开文件
{
printf("error,open file failed!\n");
exit(1);
}
printf("OK,open file successful!\n");
printf("Begin write:\n");
gets(write_buf);
count=strlen(write_buf);
if(write(fd,write_buf,count)==-1)//要写入文件的数据的字节数
{
printf("error,write file failed!\n");
exit(1);
}
printf("OK,write %d strings to file!\n",count);
return 0;
}

推荐阅读:
  1. 编写一个程序,使用getpid函数来获取当前进程的进程ID
  2. 使用read和write函数,编写一个程序,实现cp函数的基本功能

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

linux c write 函数

上一篇:MySQL MHA应用实践(方案实战)

下一篇:由12306动态验证码想到的ASP.NET实现动态GIF验证码(附源码)

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》