I've just try to check a MS Multimedia signature; specifically, a WAV file (RIFF) as a test.
So the header contains first 4-byte like: RIFF
This is my little script:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define byte char
#define word short int
#define dword int
#define DEBUG
int
main( int argc, char *argv[] )
{
FILE *file;
const char *fname = "sound.wav";
const char *mode = "rb";
byte id[4] = { 0 };
int i;
file = fopen( fname, mode );
if( file == NULL ) {
printf("[error] file not found.\n");
exit( 1 );
}
fread( id, sizeof( byte ), 4, file );
#if defined DEBUG
printf("[DEBUG]\n");
for( i = 0; i < 4; ++i )
printf("%c", id[i]);
printf("\nString: %s", id);
printf("\nLength: %d\n", strlen(id));
printf("[/DEBUG]\n");
#endif
if( 0 == strcmp( id, "RIFF") )
printf("RIFF type\n");
else
printf("non-RIFF type\n");
fclose( file );
return 0;
}
Here the result:
Code:
RIFF
String: RIFF�t ��
Length: 17
[/DEBUG]
non-RIFF type
The ID is supposed to have 4-byte size in length, but the debug result showed up w/ 17 bytes in length.
Environment: Linux/Mandriva 2k9.1
Do you know what's wrong w/ code? What's the result running under your system?
Just try w/ any WAV file.