这是我的代码:
#include <stdio.h>
#define N 4
#define A_INPUT "agents.txt"
typedef struct
{
long id;
char lastName[20];
char name[20];
char type;
int workHours;
long managId;
int sell[10];
} Agents;
Agents AgArr[N]={0};
void main()
{
int i,j=1;
FILE*agents;
agents=fopen(A_INPUT,"r");
if(agents == NULL)
{
printf("Unable to open file.\n");
exit();
}
for (i=0; i<N; i++)
{
fscanf(agents, "%ld", &AgArr[i].id);
fscanf(agents, "%s", &AgArr[i].lastName);
fscanf(agents, "%s", &AgArr[i].name);
fscanf(agents, "%c", &AgArr[i].type);
fscanf(agents, "%d", &AgArr[i].workHours);
fscanf(agents, "%ld", &AgArr[i].managId);
}
}
这是我从中读取的文本文件:
045654987 Cohen Yael P 135 302546887
024587891 Cohen Rafi F 150 -1
306354487 Gabai Shai P 112 302546887
302546887 Benzur Gadi M 130 -1
问题是数组没有得到所有文本,我得到空格和 0。如何正确扫描它?