#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); //"w" //int fd = open(argv[1], O_WRONLY | O_CREAT | O_APPEND, 0666); //"a" //printf("fd was %d\n", fd); FILE *f = fopen(argv[1], "w"); if (f == NULL) { fprintf(stderr,"Could not open file %s: ",argv[1]); perror(""); return 1; } fprintf(f, "potato\n"); fclose(f); return 0; }