The input file, card.raw is empty now. Look at the following code:
FILE *new_card = fopen(argv, "w");
As soon as you ran this code the first time, the input file card.raw was deleted and a new, empty file of the same name created. You can compare by running this command: ls -al card.raw
You need to remove this section of code from the source ...
When you put double quotes around argv, it says use this text as a literal file name, so the program goes looking for a file named argv. Since the file doesn't exist, the fopen() call fails and the file pointer is set to NULL. Then, the code prints that error message.
The seg fault is caused by the next line, fclose(input). Since the input pointer is ...
This code has an infinite loop. Look at the last while condition statement:
while (fread(buffer, 512, 1, forensic) <= 1);
What happens when the end of the input file is reached? fread will return 0, so the loop never ends! Instead, it should check for == 1.
Next, notice that every output file is 512 bytes. Remember, once the first signature is found, ...
There are several issues in this code.
First, look at how i is being incremented. Inside the code, it is incremented by 512 in several places, but it's also being incremented by 1 in the for loop setup. That will throw the alignment to 512 byte blocks off.
The test for signatures occurs in 2 places. In the first,
if (buff == 0xff && buff == ...