prince_kenshi
03-22-2001, 04:55 PM
I'm trying to create a program that will examine mpeg files and identify what layer of encoding it uses. Since mpegs have multiple segments with multiple headers, I'm making it to search for each header and identify the layering. It finds the headers by finding the 11 sync bits and the identification is masking. But when I run the program on a certain mp3, it prints a single "Layer 3" and does nothing afterward, although there is cpu activity. A simple ctrl c breaks out of it. Now I'm sure, as simple as the program is, it wouldn't take long enough for me to go to the kitchen and get something to drink before getting to the second header. I suspect it's hanging in an infinite loop somewhere. Here's the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char filename[60];
FILE *filePtr;
short int character;
short int mask_char;
printf("Enter filename: ");
scanf("%s", filename);
filePtr = fopen(filename, "rb");
if(filePtr == NULL)
{
printf("Failed to open file.");
exit(0);
}
for(character = getc(filePtr); character != EOF ;)
{
if(character==255)
{
character = getc(filePtr);
if((character & 224) == 224)
{
character &= 6;
if(character == 6)
printf("Layer 1\n");
if(character == 4)
printf("Layer 2\n");
if(character == 2)
printf("Layer 3\n");
if (character == 0)
printf("Reserved");
}
}
}
fclose(filePtr);
return 0;
}
Gracias.
#include <stdio.h>
#include <stdlib.h>
int main()
{
char filename[60];
FILE *filePtr;
short int character;
short int mask_char;
printf("Enter filename: ");
scanf("%s", filename);
filePtr = fopen(filename, "rb");
if(filePtr == NULL)
{
printf("Failed to open file.");
exit(0);
}
for(character = getc(filePtr); character != EOF ;)
{
if(character==255)
{
character = getc(filePtr);
if((character & 224) == 224)
{
character &= 6;
if(character == 6)
printf("Layer 1\n");
if(character == 4)
printf("Layer 2\n");
if(character == 2)
printf("Layer 3\n");
if (character == 0)
printf("Reserved");
}
}
}
fclose(filePtr);
return 0;
}
Gracias.