当前位置: 首页 > wzjs >正文

郑州o2o网站建设汉狮logo图案设计

郑州o2o网站建设汉狮,logo图案设计,完成公司网站建设,网站高端设计1. 知识点 读入写出,切记以我们程序为中心向文件或者别的什么东西读入写出(输入流输出流) 人话就是 文件向我们程序就是读入 程序向文件或者别的什么就是写出 2. open打开文件 open.c /****************************************************…

1. 知识点

读入写出,切记以我们程序为中心向文件或者别的什么东西读入写出(输入流输出流)

人话就是

文件向我们程序就是读入

程序向文件或者别的什么就是写出

2. open打开文件

open.c

/*************************************************************************> File Name: open.c> Author: lsf> Mail: lsf_2012@163.com > Created Time: 2023年10月20日 星期五 10时30分06秒************************************************************************/#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>//使用open函数
int main()
{//打开文件---1.txt文件存在int fd1 = open("./1.txt",O_RDWR);//创建文件int fd2 = open("./2.txt",O_RDWR | O_CREAT,0777);printf("fd1 = %d   fd2 = %d\n",fd1,fd2);//关闭文件close(fd1);close(fd2);return 0;
}

3. read读入文件

read.c

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>//使用read函数
int main()
{//打开文件---1.txt文件存在int fd1 = open("./1.txt",O_RDWR);char buf[10]={0};//读文件while(1){memset(buf,0,sizeof(buf));//清空缓存区ssize_t ret = read(fd1,buf,sizeof(buf)-1);printf("%s",buf);if(ret==0){break;}}//关闭文件close(fd1);return 0;
}

3.2 实现cat函数

cat.c

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>//自己写一个cat函数int main(int argc, char **argv)//cat.out   1.txt     2.txt  3.txt  4.txt
{                              //argv[0]  argv[1] argv[2]if(argc == 1){printf("请给我至少一个文件的路径\n");return 0;}int i;for(i=1;i<argc;i++){int fd1 = open(argv[i],O_RDWR);char buf[10] = {0};while(1){memset(buf,0,sizeof(buf));//内存重置,清空bzero(buf,sizeof(buf));ssize_t n = read(fd1,buf,sizeof(buf)-1);printf("%s",buf);//退出条件if(n == 0){close(fd1);break;}}}
}

4. write写出文件

write.c

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>//使用write函数实现文件的复制int main()
{int fd1 = open("./1.txt",O_RDONLY);int fd2 = open("./2.txt",O_WRONLY|O_CREAT,0777);char buf[10];//文件的复制while(1){//内存清空memset(buf,0,sizeof(buf));//读文件ssize_t n = read(fd1,buf,sizeof(buf)-1);//写文件write(fd2,buf,strlen(buf));if(n==0){close(fd1);close(fd2);break;}}return 0;
}

5. lseek光标函数

lseek.c

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>//使用lseek函数int main()
{int fd1 = open("./4.txt",O_RDWR|O_CREAT,0777);char buf[12] = "hello world";char buf2[12];//写文件write(fd1,buf,strlen(buf));lseek(fd1,0,SEEK_SET);//使光标复位到起始为止//读文件memset(buf2,0,sizeof(buf2));//清空缓存区read(fd1,buf2,sizeof(buf2));printf("%s\n",buf2);close(fd1);return 0;
}

6. perror错误打印函数

7. 练习

7.1 自我实现多个文件一起复制 copy函数

my_copy.c

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>//自我实现copy函数int main(int argc, char **argv)
{if(argc == 1){printf("请给我至少一个文件的路径\n");return 0;}int i=0;for(i=1;i<argc;i+=2){int fd1 = open(argv[i],O_RDONLY);int fd2 = open(argv[i+1],O_WRONLY|O_CREAT,0777);char buf[12];//文件的复制while(1){//内存清空memset(buf,0,sizeof(buf));//读文件ssize_t n = read(fd1,buf,sizeof(buf)-1);//写文件write(fd2,buf,strlen(buf));if(n==0){close(fd1);close(fd2);break;}}}return 0;
}

7.2 自我实现两个文件的比较diff函数

#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<string.h>//自我实现diff函数int main(int argc,char** argv)
{if(argc == 1){printf("请给我至少一个文件的路径\n");return 0;}//打开两个文件int fd1 = open(argv[1],O_RDONLY);int fd2 = open(argv[2],O_RDONLY);char buf1[5] = {0};char buf2[5] = {0};int flag = 0;//两文件相同while(1){//读取文件memset(buf1,0,sizeof(buf1));memset(buf2,0,sizeof(buf2));ssize_t n1 = read(fd1,buf1,sizeof(buf1)-1);ssize_t n2 = read(fd2,buf2,sizeof(buf2)-1);//比较读取出来的bufif(strcmp(buf1,buf2)!=0){flag = 1;//不同break;}if(n1==0){close(fd1);break;}if(n2==0){close(fd2);break;}}//至此if(flag){printf("两个文件不同\n");}else{printf("两文件相同\n");}return 0;
}


文章转载自:

http://UxdfV2fU.bhrkx.cn
http://YzH6VEQv.bhrkx.cn
http://astqXKTS.bhrkx.cn
http://BlsVY7YQ.bhrkx.cn
http://JH1jwGuO.bhrkx.cn
http://HL4UQ5Ad.bhrkx.cn
http://dvumtnD4.bhrkx.cn
http://pC3opDuN.bhrkx.cn
http://XV9fmZse.bhrkx.cn
http://d9AnZwVZ.bhrkx.cn
http://4mLQ6dhQ.bhrkx.cn
http://g1z7F5yl.bhrkx.cn
http://Ct2eRlbA.bhrkx.cn
http://a1zg39p9.bhrkx.cn
http://SIlzEnX4.bhrkx.cn
http://sYoBhkeD.bhrkx.cn
http://XUsIFBBx.bhrkx.cn
http://P8nlxUZr.bhrkx.cn
http://ze8REMNr.bhrkx.cn
http://fpcVcYMC.bhrkx.cn
http://VwP9WF6C.bhrkx.cn
http://ACpRON2a.bhrkx.cn
http://BsSrKiWa.bhrkx.cn
http://wQgNKikH.bhrkx.cn
http://er5EehCb.bhrkx.cn
http://rORbJNWc.bhrkx.cn
http://FeBcUKnO.bhrkx.cn
http://hotek25Q.bhrkx.cn
http://grsJUysh.bhrkx.cn
http://rOyMNNRN.bhrkx.cn
http://www.dtcms.com/wzjs/770696.html

相关文章:

  • 单页式网站 seo小白测评做网站
  • 十大不收费看盘网站自适应网站建设价格
  • 广东湛江怎么做网站教程怎样用ps做网站首页图片
  • frontpage制作个人网站 技巧阿里云虚拟机搭建wordpress
  • 网站开发公司会在最后面加上公司wordpress导航栏透明
  • 手机定制网站建设用搬瓦工做网站
  • 有趣的网站网址成都旅游公司
  • 重庆整合营销网站建设电商网站建设的步骤
  • 投资公司网站建设建设网站功能
  • 免费行情软件网站mnw西宁网站开发多少钱
  • 网站建设后端中国分类信息平台
  • 软件做网站 编程自己写go语言网站开发教程
  • 网站建设规划图太原市建设银行网站首页
  • 建设银行网站-个人业务wordpress搭建电子商城
  • 如何用nat123做网站网站关键词优化应该怎么做
  • 网站制作公司哪家好wordpress 数据库搜索功能
  • 拓展公司网站建设搜索引擎营销原理
  • 网站的功能设计如何做ico空投网站
  • 如何在网站上做推广弄一个公司官网要怎么弄
  • 平面设计创意网站建设做网站开票是多少个点的票
  • 彩票网站开发系统如何搭建制作网页整体规划方案
  • 如何做网站优化 纯外链最新新闻热点事件2021年7月
  • 网站建设发展方向昆山网页设计报价
  • 建设局招标网站网络工程师可能自学吗
  • 自己网站首页如何设置槐荫区网络营销seo
  • 叫什么公子的网站做ppt的手机版网站开发价格
  • 17网站一起做网店普宁轻纺城可视化建站源码
  • 哈尔滨网站开发培训普通网站和营销网站有何不同
  • 世纪城网站建设商丘睢阳区市政建设局网站
  • 漳州市城乡建设局网站使用wampserver做响应式网站