#include #include void print_to_start(char *path, unsigned char byte); int main(int argc, char *argv[]) { if (argc <= 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } unsigned char byte = strtoul(argv[2], NULL, 0); print_to_start(argv[1],byte); return 0; } // Add the given byte to the beginning of the given file // You may use a temp file void print_to_start(char *path, unsigned char byte){ FILE *file_reader = fopen(path, "r"); FILE *tmp_writer = fopen("f.tmp", "w"); fputc(byte, tmp_writer); int curr_byte; while ((curr_byte = fgetc(file_reader)) != EOF) { fputc(curr_byte, tmp_writer); } fclose(file_reader); fclose(tmp_writer); //rename("f.tmp", path); FILE *file_writer = fopen(path, "w"); FILE *tmp_reader = fopen("f.tmp", "r"); while ((curr_byte = fgetc(tmp_reader)) != EOF) { fputc(curr_byte, file_writer); } fclose(file_writer); fclose(tmp_reader); }