This chunk of code is supposed to display the layout of an MP3 frame header, but what is diplayed is wrong!
The layout of an mp3 header is detailled in
http://www.mp3-tech.org/programmer/frame_header.html
and here are my code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
typedef struct{
long Sync;
int id;
int layer;
int Protection_bit;
int bitrate;
int frequency;
int padding_byte;
int private_bit;
int mode;
int mode_extension;
int copyright_bit;
int home;
int emphasis;
} mp3_header;
mp3_header* lire(char *nom);
main(void)
{
char nom[100];
mp3_header* mp3;
printf("Veuillez entrer le nom et le chemin du file sans l'extension\n");
gets(nom);
strcat(nom,".mp3");
mp3 = lire(nom);
printf(" le Sync est: %d \n ",&mp3->Sync);
printf(" le id est: %d \n",&mp3->id);
printf(" le layer est: %d \n",&mp3->layer);
printf(" le Protection_bit est: %d \n",&mp3->Protection_bit);
printf(" le bitrate est: %d \n",&mp3->bitrate);
printf(" le frequecy est: %d \n",&mp3->frequency);
printf(" le padding_byte est: %d \n",&mp3->padding_byte);
printf(" le private_bit est: %d \n",&mp3->private_bit);
printf(" le mode: %d \n",&mp3->mode);
printf(" le mode_extension est: %d \n",&mp3->mode_extension);
printf(" le copyright_bit est: %d \n",&mp3->copyright_bit);
printf(" le home est: %d \n",&mp3->home);
printf(" le emphasis est: %d \n",&mp3->emphasis);
}
mp3_header* lire (char *nom)
{
mp3_header *mp3;
FILE *fichier;
mp3=(mp3_header*)malloc(sizeof(mp3_header));
fichier= fopen(nom, "r");
if (fichier== NULL)
{
printf("Erreur lecture \n");
exit(1);
}
fread (&mp3->Sync,sizeof(long),1,fichier);
fread (&mp3->id,sizeof(int),1,fichier);
fread (&mp3->layer,sizeof(int),1,fichier);
fread (&mp3->Protection_bit,sizeof(int),1,fichier);
fread (&mp3->bitrate,sizeof(int),1,fichier);
fread (&mp3->frequency,sizeof(int),1,fichier);
fread (&mp3->padding_byte,sizeof(int),1,fichier);
fread (&mp3->private_bit,sizeof(int),1,fichier);
fread (&mp3->mode,sizeof(int),1,fichier);
fread (&mp3->mode_extension,sizeof(int),1,fichier);
fread (&mp3->copyright_bit,sizeof(int),1,fichier);
fread (&mp3->home,sizeof(int),1,fichier);
fread (&mp3->emphasis,sizeof(int),1,fichier);
fclose(fichier);
return mp3;
}
So please, can anyone help me to make it work??