Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- #define ARG_ERROR "WRONG NR. OF ARGS!\n"
- #define EVER ;;
- FILE *openFile(const char path[], const char mode[]) {
- FILE *file = fopen(path, mode);
- if (file == NULL) {
- perror("");
- exit(EXIT_FAILURE);
- }
- return file;
- }
- void closeFile(FILE *file) {
- if (fclose(file) == EOF) {
- perror("");
- }
- }
- int main(int argc, char *argv[]) {
- if (argc < 3) {
- fprintf(stderr, ARG_ERROR);
- exit(-1);
- }
- FILE *file1 = openFile(argv[1], "rb");
- FILE *file2 = openFile(argv[2], "rb");
- uint8_t byte1, byte2;
- for (EVER) {
- fread(&byte1, sizeof(uint8_t), 1, file1);
- fread(&byte2, sizeof(uint8_t), 1, file2);
- if (byte1 != byte2) {
- const long offset = ftell(file1);
- printf("%08ld: %02x %02x\n", offset, byte1, byte2);
- }
- if (byte1 == 0xA) {
- fread(&byte1, sizeof(uint8_t), 1, file1);
- break;
- }
- if (byte2 == 0xA) {
- fread(&byte2, sizeof(uint8_t), 1, file2);
- break;
- }
- }
- while (fread(&byte1, sizeof(uint8_t), 1, file1)) {
- const long offset = ftell(file1);
- printf("%08ld: %02x \n", offset, byte1);
- }
- while (fread(&byte2, sizeof(uint8_t), 1, file2)) {
- const long offset = ftell(file2);
- printf("%08ld: %02x\n", offset, byte2);
- }//*/
- closeFile(file1);
- closeFile(file2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement