Write operations
1#include <stdio.h>2#include <stdlib.h>3#include <fcntl.h>4#include <unistd.h>5 voidError_handling (Char*message);6 7 intMain ()8 {9 intFD;Ten CharBuf[] ="Let ' s go!"; One AFD = open ("1.txt", o_creat|o_wronly); - if(FD = =-1) -Error_handling ("Open Error"); theprintf"file descriptor:%d \ n", FD); - - if(Write (Fd,buf,sizeof(BUF)) == -1) -Error_handling ("Write Error"); + - Close (FD); + return 0; A } at - voidError_handling (Char*message) - { - fputs (message,stderr); -FPUTC ('\ n', stderr); -Exit1); in}
Write operations
1#include <stdio.h>2#include <stdlib.h>3#include <unistd.h>4#include <fcntl.h>5 voidError_handling (Char*message);6 7 intMain ()8 {9 intFD;Ten Charbuf[ -]; OneFD = open ("1.txt", o_rdonly); A if(FD = =-1) -Error_handling ("Open Error"); -printf"file description;%d\n", FD); the - if(Read (Fd,buf,sizeof(BUF)-1)==-1) -Error_handling ("Read Error"); - +printf"file data:%s\n", buf); - Close (FD); + return 0; A } at - voidError_handling (Char*message) - { - fputs (message,stderr); -FPUTC ('\ n', stderr); -Exit1); in}
Socket Learning Note--io Basic operation (read, write)