C语言模拟实现(四)-----利用open、read、write等系统调用函数实现cp(文件复制)功能
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                C语言模拟实现(四)-----利用open、read、write等系统调用函数实现cp(文件复制)功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                話不多說,直接上代碼!
#include <sys/types.h> #include <sys/stat.h> #include <unistd.h> #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h>int main(int argc,char* argv[]){int fd,fd1,fd2;char bufs[20];int len;if(argc != 3){ printf("參數不對\n");}else{fd = open(argv[1],O_RDONLY|O_CREAT);if(fd != -1){fd1 = creat(argv[2],0775);if(fd1 != -1){fd2 = open(argv[2],O_WRONLY); while((len = read(fd,bufs,20))>0){write(fd2,bufs,len);}}else{printf("創建文件失敗\n");}}else{printf("要復制的文件不存在\n");}}return 0; }?
總結
以上是生活随笔為你收集整理的C语言模拟实现(四)-----利用open、read、write等系统调用函数实现cp(文件复制)功能的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 什么是中台业务架构?
- 下一篇: 互联网日报 | 6月23日 星期三 |
