私は一般的に新しいプログラマーで、c で作業を開始しました。IDEv3 mp3 タグをデコードしようとしていますが、さまざまな問題に遭遇しました。fread() および strncpy() コマンドを使用しているときに、どちらも終了参照点として \n 文字が必要であることに気付きました。(たぶん私は間違っているかもしれませんが、これは単なる観察です)
出力を印刷すると、判読できない文字が生成されます。この問題を解決するための解決策として、(8)\n 文字 (バイト全体) を生成するために 3 バイトではなく 4 バイトに fread() を使用しています。印刷に使用しているメモリ。理論的には、fread() を使用している場合、この問題は発生しないはずです。
コードのサンプル:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
unsigned char header_id[3]; /* Unsigned character 3 Bytes (24 bits) */
}mp3_Header;
int main (int argc, char *argv[]) {
mp3_Header first;
unsigned char memory[4];
FILE *file = fopen( name.mp3 , "rb" );
if ( (size_t) fread( (void *) memory , (size_t) 4 , (size_t) 1 , (FILE *) file) !=1 ) {
printf("Could not read the file\n");
exit (0);
} /* End of if condition */
strncpy( (char *) first.header_id , (char *) memory , (size_t) 3);
printf ("This is the header_ID: %s\n", first.header_id);
fclose(file);
} /* End of main */
return 0;