Hi,
1)
Code:
if (fp== NULL)
{
printf("Could not open file \n");
return 1;
}
This should go
before the loop.
2)
Code:
while (feof(fp) == false)
Please note that
feof() will only return true after you have attempted to read past the end of the file. So your loop will run one more iteration then you would expect.
3)
Code:
if(buffer[0]==0xff && buffer[1]==0xd8 && buffer[2]==0xff && (buffer [3]==0xff || buffer[3]==0xe1))
Notice the bold part. Shouldn't it be
0xe0? Anyway, maybe it would be more readable if you just defined the expected header sequence as an array/string and use something like
strncmp() for the comparison.
4) why is the comparison in every iteration? Does the file have a header each 512 bytes?
5)
Code:
if (outfile == NULL)
{
printf("could not create jpeg file\n");
return 2;
}
Again, you should check this
before you attempt to write to the file.
6)
why the '&' ?
7) You open a new file in each of the 51 iterations of the inner loop. But you only
fclose() once.
8) What is this program supposed to do in the first place?