このコードは、1つのmp3ファイルID3V1タグを読み取るように動作します。しかし、MP3ファイルが少ないディレクトリがあります。私は自分のプログラムがディレクトリにあるすべてのMP3ファイルを読むことを可能にする何かを追加したいと思います。 そして、すべてのID3V1タグをCSVファイルに書き出す必要があります。いくつかのMP3ファイルのタグを読み取る
私はそれを行う方法がわかりません、どんな助けにも感謝します。
#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)
{
printf("Please choose one file: %s <song.mp3> \n", argv[0]);
} type FILE,
file = fopen("song.mp3", "rb");
if (file == NULL) {
printf("I couldn't open: %s for reading.\n");
exit(0);
}
else
{
mp3Info tag_in;
fseek(file, -sizeof(mp3Info), SEEK_END);
if (fread(&tag_in, sizeof(mp3Info), 1, file) != 1)
{
printf("Could not read the tag\n");
exit (0);
}
if (memcmp(tag_in.tag, "TAG", 3) == 0)
{
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;
}
}
}
これは動作ですが、私は問題があります:fprintf(これは例です) 私の変数 "this is an example"はスペースのため4つのケースに分かれていますが、どうすれば修正できますか? – Joys
ポイント4ページ2の[RFC4180の文書](https://tools.ietf.org/html/rfc4180)で指定されているように、それは起こらないはずです。 'スペースはフィールドの一部とみなされ、無視してはいけません」。また、行の最後にコンマを置くことはできません。したがって、次のコードを実行すると、fprintf(file、field1、field2 with spaces、field3 \ n ");とうまくいくはずです。最後に改行を忘れないでください。 – saeleko
また、私の答えで言ったように、Excelを使うなら、最初の行に 'sep =、'を追加することを忘れないでください。これは、私の完全な例が 'fprintf(file、" sep =、\ nfield1、フィールド2にスペース、フィールド3 \ n ");'。 – saeleko