(Linux高級編程)讀寫文件

#include <sys/types.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc,char *argv[])
{
    char buf[100] = {0};
	int i,n;
	int fd = open(argv[1],O_RDONLY);
	while(n = read(fd,buf,sizeof(buf)))//讀取完成後的結束標誌爲n等於0
	{
        write(1,buf,n);
	}
	close(fd);
	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章