@Blauelf is correct: you can't count on char
to be an unsigned 8-bit int.
However, you can use a typedef
to make certain that a BYTE
is really a byte.
Look at these type definitions, borrowed from bmp.h
:
#include <stdint.h>
/**
* Common Data Types
*
* The data types in this section are essentially aliases for C/C++
* primitive data types.
*
* Adapted from http://msdn.microsoft.com/en-us/library/cc230309.aspx.
* See http://en.wikipedia.org/wiki/Stdint.h for more on stdint.h.
*/
typedef uint8_t BYTE; // You can use this one in recover.c
typedef uint32_t DWORD;
typedef int32_t LONG;
typedef uint16_t WORD;
Note: I just looked back at your other questionyour other question and saw that you are already using this in your jpg.h
file. It would be sufficient to include the typedef
directly in recover.c
and avoid defining another struct
here.
In other news, you're still over-complicating your approach. For example, if you are reading your data stream into a 512-byte buffer, you do not need to copy the first four bytes of your buffer into another array before comparing them to your JPEG signature. You can just compare the first four bytes of your buffer to the JPEG signature directly.
There's more than one way to do this. Here's one way to approach it using an array:
// JPEG signature
BYTE jpgSig[3] = { 0xff, 0xd8, 0xff };
Then, you could write a function to check the first three bytes like so:
bool jpgCheck(BYTE data[], BYTE jpgSig[])
{
for (int i = 0; i < 3; i++)
{
if ((data[i]) != (jpgSig[i]))
{
return false;
}
}
return true;
}
This is an incomplete solution (it still does not check for all the possible values of the fourth byte) but it should be enough to get you started.
Don't forget to accept the most helpful answer to each of your questions by clicking the green check mark; otherwise they will always be marked as unanswered questions, and they will clutter the forum. Fight Zombie Questions!