高手求助~~编译出错,记忆体不能written,请指出问题所在!
//cmp.c 讀ID3V2並歸檔相應信息。#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<ctype.h>
#define SIZE 1024
void search(FILE *fp1,FILE *fp2,FILE *fp3,FILE *fp4)
{
int count,i,j=0,flag=0;
char ch=0;
char pear[7][4]={"TALB","TYER","TCON","TPE1","TIT2","TRCK","USLT"},apple[5*SIZE];
rewind(fp2);
fputc('\t',fp2); //write into sql1.txt
rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch&&(flag!=1))
{
count=0;
while((((char)9)!=ch)&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[0],4))) //ok
{
// printf("compare right!"); //ok
flag=1;
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,(count-4),1,fp2); //第一字段信息已輸出
fputc((char)9,fp2);
//
//
}//ifover
memset(apple,0,sizeof(apple));
// while(i>totalsize-10) break;
ch=fgetc(fp1);
}//whileover
rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch)
{
count=0;
while(((char)9)!=ch&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[1],4))) //ok
{
// printf("compare right!"); //ok
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,count-4,1,fp2); //第一字段信息已輸出
fputc((char)9,fp2);
// ++j;
// if(j>=3) break;
}//ifover
memset(apple,0,sizeof(apple));
// printf("not found!\n");
// if(j>=3) break;
// while(i>totalsize-10) break;
ch=fgetc(fp1);
}//whileover
rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch)
{
count=0;
while(((char)9)!=ch&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[2],4))) //ok
{
// printf("compare right!"); //ok
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,count-4,1,fp2); //第一字段信息已輸出
fputc((char)9,fp2);
// ++j;
// if(j>=3) break;
}//ifover
memset(apple,0,sizeof(apple));
// printf("not found!\n");
// if(j>=3) break;
// while(i>totalsize-10) break;
ch=fgetc(fp1);
}//whileover
// fputc('\n',fp2);
fputc('\t',fp3); // writer into sql2.txt
rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch)
{
count=0;
while(((char)9)!=ch&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[3],4))) //ok
{
// printf("compare right!"); //ok
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,count-4,1,fp3); //第一字段信息已輸出
fputc((char)9,fp3);
fputc((char)9,fp3);
fputc((char)9,fp3);
// ++j;
// if(j>=3) break;
}//ifover
memset(apple,0,sizeof(apple));
// printf("not found!\n");
// if(j>=3) break;
// while(i>totalsize-10) break;
ch=fgetc(fp1);
}//whileover
fputc('\t',fp4); // writer into sql3.txt
rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch)
{
count=0;
while(((char)9)!=ch&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[4],4))) //ok
{
// printf("compare right!"); //ok
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,count-4,1,fp4); //第一字段信息已輸出
fputc((char)9,fp4);
// ++j;
// if(j>=3) break;
}//ifover
memset(apple,0,sizeof(apple));
// printf("not found!\n");
// if(j>=3) break;
// while(i>totalsize-10) break;
ch=fgetc(fp1);
}//whileover
// fputc('\t',fp4); // writer into sql3.txt
rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch)
{
count=0;
while(((char)9)!=ch&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[5],4))) //ok
{
// printf("compare right!"); //ok
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,count-4,1,fp4); //第一字段信息已輸出
fputc((char)9,fp4);
// ++j;
// if(j>=3) break;
}//ifover
memset(apple,0,sizeof(apple));
// printf("not found!\n");
// if(j>=3) break;
// while(i>totalsize-10) break;
ch=fgetc(fp1);
}//whileover
// fputc('\t',fp4); // writer into sql3.txt
/* rewind(fp1);
ch=fgetc(fp1);
while('%'!=ch)
{
count=0;
while(((char)9)!=ch&&('%'!=ch))
{
apple[count]=ch;
// printf("%c",apple[count]); //ok
++count;
ch=fgetc(fp1);
}//whileover //ok
// printf("%ld ",ftell(fp1));
if(0==(memcmp(apple,pear[6],4))) //ok
{
printf("compare right!"); //ok
for(i=0;i<=count-4;++i)
{
apple[i]=apple[i+5];
}
fwrite(apple,count-4,1,fp4); */ //第一字段信息已輸出
fputc((char)9,fp4);
fputc((char)9,fp4);
fputc((char)9,fp4);
fputc((char)9,fp4);
// fputc((char)9,fp4);
// ++j;
// if(j>=3) break;
/* }//ifover
memset(apple,0,sizeof(apple));
// printf("not found!\n");
// if(j>=3) break;
while(i>totalsize-10) break;
}//whileover*/
ch=fgetc(fp1);
// fputc('\n',fp2);
}//oversearch
int main(void)
{
FILE *fp1,*fp2,*fp3,*fp4;
if(NULL==(fp1=fopen("test.txt","at+")))
{
printf("cannot write the file\n");
exit(0);
}
if(NULL==(fp2=fopen("sql1.txt","at+")))
{
printf("cannot write the file\n");
exit(0);
}
if(NULL==(fp3=fopen("sql2.txt","at+")))
{
printf("cannot write the file\n");
exit(0);
}
if(NULL==(fp4=fopen("sql3.txt","at+")))
{
printf("cannot write the file\n");
exit(0);
}
search(fp1,fp2,fp3,fp4);
fclose(fp2);
fclose(fp3);
fclose(fp4);
fclose(fp1);
return 0;
}