I am currently trying to create a binary byte patcher but got stuck at one little issue. When trying to read the input file byte by byte and simultanously writing these bytes to an output file, newline characters are somehow doubled.
An input like that:
line1
line2
line3
Would look like:
line1
line2
line3
The actual program is a bit more complex but this abstract should give an idea of what I'm trying to do.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SECTOR 32
int main(int argc, char** argv) {
FILE* input = fopen(INPUT_FILE, "r");
FILE * output = fopen(OUTPUT_FILE, "w");
int filesize = size of opened file...
char buffer[16] = {0};
int i = 0;
while(i < filesize) {
fseek(input, i, SEEK_SET);
fread(buffer, sizeof(char), SECTOR, input);
if(cmp buffer with other char array) {
do stuff
} else {
i++;
fwrite(&buffer[0], sizeof(char), 1, output);
}
}
print rest of buffer to the file to have the past SECTOR-1 bytes aswell...
fclose(input);
fclose(output);
return 1;
}