最近学习linux-c的编程
生活随笔
收集整理的這篇文章主要介紹了
最近学习linux-c的编程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
2019獨角獸企業重金招聘Python工程師標準>>>
最近使用linux-c編程
學習了下文件的讀寫,如果說一切都是文件的話,linux-c的文件系統可以被抽象為這五個函數
open,read,write,close,fcntl.
是不是一切的計算系統都可以理解為這幾部分呢。輸入,算法,輸出。
附上代碼
#include?<stdio.h> #include?<unistd.h> #include?<stdlib.h> #include?<sys/types.h> #include?<sys/stat.h> #include?<fcntl.h>//todo?add?othor?function? //open(file,mode,flag),read(fd,buf,size),write(fd,buf,size),close(fd) int?main(int?argc,?char?const?*argv[]) {int?fd,size,check_flag;char?mesg[]?=?"a?lot?mesg?on?unix?open";char?buffer[80];char?*host_str;check_flag?=?access("test_open.txt",R_OK);if?(check_flag?!=0){fd?=?open("test_open.txt",O_WRONLY|O_CREAT,S_IRWXU);if(fd?<?0){printf("open?&?create?faild?\n");exit(-1);}size?=?write(fd,mesg,sizeof(mesg));close(fd);}fd?=?open("/etc/hosts",O_RDONLY);if(fd?<?0){printf("open??faild?\n");exit(-1);}//read(fd,buffer,sizeof(buffer));while(?(size?=?read(fd,buffer,sizeof(buffer))?)?>?0){printf("%s\n",?host_str);}close(fd);printf("end\n");return?0; }轉載于:https://my.oschina.net/u/218155/blog/540334
總結
以上是生活随笔為你收集整理的最近学习linux-c的编程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 获取进程号并赋值判断进程状态
- 下一篇: 每日更新