/* this source file demonstrates (1) how to open,read file and create it if not exist; (2) how to print different formats of an integer (3) how to create a directory and set a specific mode */ #include <fcntl.h> /*open()*/ #include <unistd.h> /*close()*/ #include <stdio.h> /*printf()*/ #include <stdlib.h> /*system() and many other :) */ #include <string.h>/*strlen()*/ #include <sys/stat.h> /*mkdir*/ int main() { int fd,fe,z,k=520; char s[50],c[20]; fd=open("./pass",O_CREAT|O_RDWR|O_APPEND,0600);/*fd is a file descriptor*/ if(fd<0) printf("can not open/create file/n"); else { printf("write something?:/n"); scanf("%s",s); z=write(fd,s,strlen(s)); if(z<0) printf("can not write~/n"); close(fd);/*don't forget*/ } fd=open("/etc/passwd",O_RDONLY); fe=open("./pass2",O_CREAT|O_RD