Hello everyone,
I am a beginner in programming and I have an assignment from my university to wright a code in C for reading mp3 files in ID3V2 format. I have searched the web and tried to put together some pieces and I came up with this code. Although that I have put many error warnings from top to bottom I can not still understand where is the mistake.
My first problem is that the code it compiles with only one warning:
warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]
Unfortunately I do not know what is my mistake here. I am trying to print the input of the user in case of a mistake, thought by doing this I get this warning.
My second problem is when I am executing the code I get as an output:
The program has failed to get the Tags
Any help would much appreciated.
Thank you in advance for your time reading my problem.
Best Regards,
Thanos
I am a beginner in programming and I have an assignment from my university to wright a code in C for reading mp3 files in ID3V2 format. I have searched the web and tried to put together some pieces and I came up with this code. Although that I have put many error warnings from top to bottom I can not still understand where is the mistake.
My first problem is that the code it compiles with only one warning:
warning: format ‘%s’ expects a matching ‘char *’ argument [-Wformat]
Unfortunately I do not know what is my mistake here. I am trying to print the input of the user in case of a mistake, thought by doing this I get this warning.
My second problem is when I am executing the code I get as an output:
The program has failed to get the Tags
Any help would much appreciated.
Thank you in advance for your time reading my problem.
Best Regards,
Thanos
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct{
char tag[3];
char title[30];
char artist[30];
char album[30];
char year[4];
char comment[30];
unsigned char genre;
}mp3Info;
int main (int argc, char *argv[])
{
if ( argc != 1 ) /* Input from user argc should be 1 for correct
* execution. The argument count variable
* stores the number of arguments plus one. */
{
/*We print argv[0], if the program that user has chosen for
* execution it is not correct as input if has more inputs*/
printf( "Please choose one file: %s <silence.mp3> \n", argv[0] );
}
else
{
FILE *file; /* A file pointer is a variable of type FILE,
* we declare a file pointer.*/
file = fopen("silence.mp3", "rb"); /* Open the file
* silence.mp3 in
* "reading" mode "r". */
if (file == NULL) {
/* If the file could not open for a variety of reasons
* the program should inform us by print the document
* and exit.*/
printf("I couldn't open: %s for reading.\n");
exit(0);
}
else
{
mp3Info tag_in;
/* Set the fseek to the beggining of the document with
* the help of the command SEEK_SET, condition if fail*/
if (fseek(file, 0 *sizeof(mp3Info), SEEK_SET) == -1)
{
fprintf(stderr, "Not able to fseek");
return EXIT_FAILURE;
}
/* Read the first name "tag" */
if (fread(&tag_in, sizeof(mp3Info), 1, file) != 1)
{
printf("Could not read the tag\n");
exit (0);
}
/* Compare memory areas for verification */
if (memcmp(tag_in.tag, "TAG", 3) == 0)
{
/* Verify that names are where as we expect */
printf("Title: %.30s\n", tag_in.title);
printf("Artist: %.30s\n", tag_in.artist);
printf("Album: %.30s\n", tag_in.album);
printf("Year: %.4s\n", tag_in.year);
if (tag_in.comment[28] == '\0')
{
printf("Comment: %.28s\n", tag_in.comment);
printf("Track: %d\n", tag_in.comment[29]);
}
else
{
printf("Comment: %.30s\n", tag_in.comment);
}
printf("Genre: %d\n", tag_in.genre);
}
else
{
fprintf(stderr, "The program has failed to get the Tags\n");
return EXIT_FAILURE;
}
fclose(file);
return 0;
}
}
}