学员小问题,在线等,急
我想写个程序,利用fgets读取文档中每一行录入数组中,最后再录入结构体中,可测试时就是输出不出来,怎么办,求大佬们帮帮我。
文档中字符串是以\t 隔开的。
#include <stdio.h>
#include <stdlib.h>
struct YC
{
char name[30];
char Cp_cn[80];
char Cp[80];
char N[500];
};
int main()
{
struct YC A[10000];
FILE *fp =fopen("Herb_Compound.txt","r");
if((fp=fopen("Herb_Compound.txt","r"))==NULL)
{
printf("Can not open file\n");
}
char a[1000];
int i=0,j=0,e=0,f=0,p=0,q=0;
while(!feof(fp))
{
fgets(a,500,fp);
while(a[i]!='\t')
{
A[j].name[q]=a[i];
i++;
q++;
}
while(a[i]='\t')
{
i++;
}
while(a[i]!='\t')
{
A[j].Cp_cn[e]=a[i];
e++;
i++;
}
while(a[i]='\t')
{
i++;
}
while(a[i]!='\t')
{
A[j].Cp[f]=a[i];
f++;
i++;
}
while(a[i]='\t')
{
i++;
}
while(a[i]!='\n')
{
A[j].N[p]=a[i];
p++;
i++;
}
j++;
i=0;
}
for(int i=0;i<j;i++)
{
for(int w=0;i<q;i++)
{
printf("%c",A[j].name[i]);
}
printf(" ");
for(int w=0;i<e;i++)
{
printf("%c",A[j].Cp_cn[i]);
}
printf(" ");
for(int w=0;i<f;i++)
{
printf("%c",A[j].Cp[i]);
}
printf(" ");
for(int w=0;i<p;i++)
{
printf("%c",A[j].N[i]);
}
printf("\n");
}
return 0;
}