如题,大一新生+新手,刚接触C,请吧里大神帮看看。
代码如下:
int print_id3(char* filename)
{
size_t size1,size2,size3,size4,size5,size6;
struct id3tag tag;
FILE *fp;
int ret=0;
if(!filename) return 1;
fp = fopen(filename,"r");
if(!fp) return 1;
fseek(fp,-128*sizeof(char),SEEK_END);
fread((void *)tag.header,sizeof(char),3,fp);
if(!(tag.header[0] == 'T'
&& tag.header[1] == 'A'
&& tag.header[2] == 'G'))
{
ret= 2;
}
else
{
size1=fread((void *)tag.title,sizeof(char),30,fp);
size2=fread((void *)tag.artist,sizeof(char),30,fp);
size3=fread((void *)tag.album,sizeof(char),30,fp);
size4=fread((void *)tag.year,sizeof(char),4,fp);
size5=fread((void *)tag.comment,sizeof(char),30,fp);
size6=fread((void *)tag.genre,sizeof(char),1,fp);
tag.title[30] = tag.artist[30] = tag.album[30] = tag.year[4] = tag.comment[30] = tag.genre[1] = 0;
unsigned char uc = (unsigned char)tag.genre[0];
if((int)size1==0&&(int)size2==0&&(int)size3==0&&(int)size4==0&&(int)size5==0&&(int)size6==0)
{
fclose(fp);
return 3;
}
else
{
printf("Songtitel : %s\n",tag.title);
printf("Interpret : %s\n",tag.artist);
printf("Album : %s\n",tag.album);
printf("Erscheinungsjahr : %s\n",tag.year);
printf("Beliebiger Kommentar: %s\n",tag.comment);
printf("Genre : %s\n",genre_list[uc]);
ret=0;
}
}
fclose(fp);
return ret;
}
要求是读取成功返回0,文件打开失败返回1,没有id3tag返回2,读取错误返回3.
但是我这代码不管怎么测试都不返回3.请大神帮看看错误在哪。谢了~
代码如下:
int print_id3(char* filename)
{
size_t size1,size2,size3,size4,size5,size6;
struct id3tag tag;
FILE *fp;
int ret=0;
if(!filename) return 1;
fp = fopen(filename,"r");
if(!fp) return 1;
fseek(fp,-128*sizeof(char),SEEK_END);
fread((void *)tag.header,sizeof(char),3,fp);
if(!(tag.header[0] == 'T'
&& tag.header[1] == 'A'
&& tag.header[2] == 'G'))
{
ret= 2;
}
else
{
size1=fread((void *)tag.title,sizeof(char),30,fp);
size2=fread((void *)tag.artist,sizeof(char),30,fp);
size3=fread((void *)tag.album,sizeof(char),30,fp);
size4=fread((void *)tag.year,sizeof(char),4,fp);
size5=fread((void *)tag.comment,sizeof(char),30,fp);
size6=fread((void *)tag.genre,sizeof(char),1,fp);
tag.title[30] = tag.artist[30] = tag.album[30] = tag.year[4] = tag.comment[30] = tag.genre[1] = 0;
unsigned char uc = (unsigned char)tag.genre[0];
if((int)size1==0&&(int)size2==0&&(int)size3==0&&(int)size4==0&&(int)size5==0&&(int)size6==0)
{
fclose(fp);
return 3;
}
else
{
printf("Songtitel : %s\n",tag.title);
printf("Interpret : %s\n",tag.artist);
printf("Album : %s\n",tag.album);
printf("Erscheinungsjahr : %s\n",tag.year);
printf("Beliebiger Kommentar: %s\n",tag.comment);
printf("Genre : %s\n",genre_list[uc]);
ret=0;
}
}
fclose(fp);
return ret;
}
要求是读取成功返回0,文件打开失败返回1,没有id3tag返回2,读取错误返回3.
但是我这代码不管怎么测试都不返回3.请大神帮看看错误在哪。谢了~