#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct
tags
{
char
title[100], artist[100], album[100],
track_num[100], year[100], genre[100];
};
void
merge_file(
char
* file1,
char
* file2,
char
* file3)
{
FILE
*f1, *f2, *f3;
int
ch;
f1 =
fopen
(file1,
"rb"
);
f2 =
fopen
(file2,
"rb"
);
f3 =
fopen
(file3,
"wb"
);
if
(f1 == NULL || f2 == NULL) {
exit
(EXIT_FAILURE);
}
while
((ch =
fgetc
(f1)) != EOF)
fputc
(ch, f3);
while
((ch =
fgetc
(f2)) != EOF)
fputc
(ch, f3);
fclose
(f1);
fclose
(f2);
fclose
(f3);
}
void
tagging(
char
* file1,
char
* file2,
char
* file3)
{
int
size = 0;
char
clean[100];
struct
tags t;
unsigned
char
pad1[7] = { 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x76 };
unsigned
char
pad2[3] = { 0x00, 0x00, 0x00 };
FILE
* f1;
f1 =
fopen
(file1,
"wb"
);
fprintf
(f1,
"ID3"
);
fwrite
(pad1,
sizeof
(pad1), 1, f1);
gets
(clean);
printf
(
"\nEnter the title of the mp3:"
);
scanf
(
"%[^\n]%*c"
, t.title);
printf
(
"\nEnter the artist of the mp3:"
);
scanf
(
"%[^\n]%*c"
, t.artist);
printf
(
"\nEnter the album of the mp3.\n"
);
scanf
(
"%[^\n]%*c"
, t.album);
printf
(
"\nEnter the year of the mp3.\n"
);
scanf
(
"%[^\n]%*c"
, t.year);
printf
(
"\nEnter the track number of the mp3.\n"
);
scanf
(
"%[^\n]%*c"
, t.track_num);
fprintf
(f1,
"TRCK"
);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
size =
strlen
(t.track_num);
size++;
fprintf
(f1,
"%c"
, size);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
fprintf
(f1,
"%s"
, t.track_num);
fprintf
(f1,
"TYER"
);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
size =
strlen
(t.year);
size++;
fprintf
(f1,
"%c"
, size);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
fprintf
(f1,
"%s"
, t.year);
fprintf
(f1,
"TIT2"
);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
size =
strlen
(t.title);
size++;
fprintf
(f1,
"%c"
, size);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
fprintf
(f1,
"%s"
, t.title);
fprintf
(f1,
"TPE1"
);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
size =
strlen
(t.artist);
size++;
fprintf
(f1,
"%c"
, size);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
fprintf
(f1,
"%s"
, t.artist);
fprintf
(f1,
"TALB"
);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
size =
strlen
(t.album);
size++;
fprintf
(f1,
"%c"
, size);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
fprintf
(f1,
"%s"
, t.album);
fprintf
(f1,
"TCON"
);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
size =
strlen
(t.genre);
size++;
fprintf
(f1,
"%c"
, size);
fwrite
(pad2,
sizeof
(pad2), 1, f1);
fprintf
(f1,
"%s"
, t.genre);
fclose
(f1);
}
int
main()
{
char
file1[100] =
"media_info.txt"
, file2[100], file3[100];
printf
(
"\nEnter the input mp3 file name\n"
);
scanf
(
"%s"
, file2);
printf
(
"\nEnter the output mp3 file name\n"
);
scanf
(
"%s"
, file3);
tagging(file1, file2, file3);
merge_file(file1, file2, file3);
return
0;
}