#include #include #include #include int main(int argc, char *argv[]){ if(argc < 2){ fprintf(stderr, "Usage %s filename\n", argv[0]); return 1; } //Open file to write //Try CREAT and TRUNC vs APPEND options //int fd = open(argv[1], O_WRONLY, 0666); //int fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0666); int fd = open(argv[1], O_WRONLY | O_CREAT | O_APPEND, 0666); //printf("fd was %d\n", fd); if (fd < 0) { fprintf(stderr,"Could not open file %s: ",argv[1]); perror("ERROR"); return 1; } write(fd, "potato\n", 7); close(fd); return 0; }