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

/*

成都网站建设哪家好,找创新互联公司!专注于网页设计、重庆网站建设公司、微信开发、小程序开发、集团成都企业网站定制等服务项目。核心团队均拥有互联网行业多年经验,服务众多知名企业客户;涵盖的客户类型包括:成都三轮搅拌车等众多领域,积累了大量丰富的经验,同时也获得了客户的一致表扬!

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

#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;
}


分享文章:使用write函数来编写一个程序,在程序中指定一个文件,用户可以向程序中一次写入不超过80个字符的数
分享链接:http://csruizhi.cn/article/iposoh.html

其他资讯

Copyright © 2007-2024 成都优众联杰科技有限公司 All Rights Reserved 蜀ICP备2024116266号
友情链接: 手机网站制作 LED网站设计方案 企业网站建设公司 手机网站建设 成都网站建设流程 重庆网站设计 企业网站建设 定制网站建设 成都企业网站制作 重庆网站建设 手机网站设计 高端定制网站设计 成都响应式网站建设 成都营销网站制作 外贸网站建设 梓潼网站设计 成都网站建设 企业网站设计 手机网站制作 成都网站建设公司 成都网站设计 高端网站设计推广