下面是一段调试程序从文件中提取数据 为什么不能提取 ?请高手给我改一下
#include<graphics.h>
#include<math.h>
main()
{
FILE *fp;
char file[10],ch,str[4];
float a[100][7]; int flag[100]; int i=1,j=1;
printf("Enter the file name:\n");
scanf("%s",file);
if ((fp=fopen(file,"r"))==NULL)
{printf ("cannot open this file\n");
exit(0);
}
ch=fgetc(fp);
getch(); printf("aaa\n");
while (ch!=EOF)
{while ((ch=fgetc(fp))=='G')
{
getch(); printf("bbb\n");
fgets (str,3,fp); printf("%s",str);
if(strcmp(str,"01")==0) {flag[i]
=1;i++;printf("01");}
else if (strcmp(str,"02")==0) {flag
[i]=2;i++;printf("02");}
else if (strcmp(str,"03")==0) {flag
[i]=3;i++;printf("03");}
else if (strcmp(str,"00")==0) {flag
[i]=0;i++; printf("00");}
else break;
getch(); printf("abdc\n");
while (ch=fgetc(fp)!='N')
{
int p=0;
char st[10];
printf("%d\n",p);
if (ch=='X') /*可能是这个地方有问题*/
{ printf("%c",ch);
ch=fgetc(fp);
while('0'<= ch && ch<='9' ||
ch=='.' )
{
p++;ch=fgetc(fp); getch();
}
fgets(st,p,fp-p);
a[i][j]=atof(st); printf("%f",a
[i][j]);
}
if (ch=='Y')
{
int j=2;
ch=fgetc(fp);
while('0'< ch && ch<'9' ||
ch=='.' )
{
p++; ch=fgetc(fp);
}
fgets(st,p,fp-p);
a[i][j]= atof(st); printf("%
f",a[i][j]);
}
getch();printf("ok\n");
}
}
}fclose(fp);
}