首页 > 其他分享 >文件IO——用read与write实现图片拷贝

文件IO——用read与write实现图片拷贝

时间:2024-06-10 12:01:06浏览次数:15  
标签:arr read res write int IO path include open

  1 #include <stdio.h>
  2 #include <sys/types.h>
  3 #include <sys/stat.h>
  4 #include <fcntl.h>
  5 #include <unistd.h>
  6 #include <string.h>
  7 int main(int argc, const char *argv[])
  8 {
  9 
 10     int path= open("./1zh.jpg",O_RDONLY);
 11     if(path < 0)
 12     {
 13         perror("open");
 14         return -1;
 15     }
 16     printf("文件打开成功\n");
 17 
 18     int path1= open("./2.jpg",O_WRONLY | O_CREAT | O_TRUNC, 0777);
 19     if(path1 < 0)
 20     {
 21         perror("open");
 22         return -1;
 23     }
 24     printf("文件打开成功\n");
 25     char arr[32] = "";
 26     ssize_t res = 0;
 27     while(1)
 28     {
 29         bzero(arr,sizeof(arr));  
 30         res = read(path,arr,sizeof(arr));
 31         if(res <0)
 32         {
 33             perror("read");
 34             return -1;
 35         }
 36         else if (res == 0)
 37         {
 38             printf("文件读取完毕\n");
 39             break;
 40         }
 41         write(path1,arr,res);
 42     }
 43     if (close(path) <0)
 44     {
 45         perror("close");
 46         return -1;
 47     }
 48     printf("文件关闭成功\n");
 49 
 50     if (close(path1) <0)
 51     {
 52         perror("close");
 53         return -1;
 54     }
 55     printf("文件关闭成功\n");
 56     return 0;
 57 }
 58 

标签:arr,read,res,write,int,IO,path,include,open
From: https://blog.csdn.net/qq_51852604/article/details/139575165

相关文章

  • 10-1:Action与Func委托
     1.Action:0到16个参数的没有返回值的泛型委托Actionaction1=()=>{};Action<int>action2=i=>Console.WriteLine(i);2.用Action类型做参数:this.DoNothing(action1);privatevoidDoNothing(Actionact){act.Invoke();......
  • Android studio 连接sqlist数据库,账号密码错误仍能登录的原因
    昨天在写Androidstudio的大作业,写到连接sqlist数据库实现登录的时候明明账号密码都不正确,但是用户却可以登录,我原先以为是我sql语句写错了,将sql语句从Cursorcursor=db.rawQuery("select*fromuserwherenamelike?andpasswordlike?",newString[]{name,password});改......
  • MySQL操作 UPDATE、SELECT、UNION、IN、DISTINCT
    update更新所有人的年龄加一:updateusersetage=age+1;只更新某个:updateusersetage=age+1wherename='zhangsan';select查询select*fromuser;//一般不建议使用通配符selectname,age,sexfromuser;//根据键查找selectname,age,sexfromuserwheresex='......
  • 吴恩达机器学习第一课 Supervised Machine Learning Regression and Classification
    SupervisedMachineLearningRegressionandClassification第一周1.1机器学习定义1.2监督学习1.2.1回归在输入输出学习后,然后输入一个没有见过的x输出相应的y1.2.2classification有多个输出1.3无监督学习数据仅仅带有输入x,但不输出标签y,算法需要找到数据中的......
  • Axios简单完成上传图片到互联网(前端)
    操作步骤很简单,需要会使用HTML,CSS,JS以及Axios和后端提供的URL接口<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0">......
  • 【简写Mybatis-02】注册机的实现以及SqlSession处理
    前言注意:学习源码一定一定不要太关注代码的编写,而是注意代码实现思想:通过设问方式来体现代码中的思想;方法:5W+1H源代码:https://gitee.com/xbhog/mybatis-xbhog;https://github.com/xbhog/mybatis-xbhog;交个朋友,有价值欢迎star。回顾&分析上一局实现Mapper接口和映射器通......
  • ApplicationContextAware获取IOC容器
    目录常见Aware实现ApplicationContextAware作用1、ApplicationContext是什么?2、ApplicationContextAware作用ApplicationContextAware使用常见Aware实现接口作用ApplicationContextAware获取当前应用的上下文对象EnvironmentAware获取环境变量,包括我们配置的以及......
  • 解决 发生异常: RuntimeError (note: full exception trace is shown but execu
    发生异常:RuntimeError(note:fullexceptiontraceisshownbutexecutionispausedat:<module>)Anattempthasbeenmadetostartanewprocessbeforethecurrentprocesshasfinisheditsbootstrappingphase.Thisproba......
  • 天才程序员周弈帆 | Stable Diffusion 解读(二):论文精读
    本文来源公众号“天才程序员周弈帆”,仅用于学术分享,侵权删,干货满满。原文链接:StableDiffusion解读(二):论文精读【小小题外话】端午安康!在上一篇文章天才程序员周弈帆|StableDiffusion解读(一):回顾早期工作-CSDN博客中,我们梳理了基于自编码器(AE)的图像生成模型的发展脉络,并......
  • CA Data Classification algorithm
    CAAssignment1DataClassification ImplementingPerceptronalgorithmAssessmentInformationAssignmentNumber1(of2)Weighting15%AssignmentCirculated10Feb2023Deadline3March2023at17:00SubmissionModeElectronicviaCanvasPurposeofassessm......