程序源码
#include<stdio.h>
#include <string.h>
#include <stdlib.h>
#define DATALEN 15
struct wordUnit{
int id;
char word[10];
char depId[10];
char pos[10];
char depRel[10];
};
int main(){
FILE *data;
int i=0;
struct wordUnit words[DATALEN];
if((data=fopen("data3.txt","r"))==NULL){
printf("Can not open file\n");
return 0;
}
while(!feof(data)){
fscanf(data,"%d %s %s %s %s\n",&words[i].id,&words[i].word,&words[i].depId,&words[i].pos,&words[i].depRel);
i++;
}
fclose(data);
for(int j=0;j<i;j++){
printf("%d %s %s %s %s\n",words[j].id,words[j].word,words[j].depId,words[j].pos,words[j].depRel);
}
return 0;
}
测试结果

读取的txt文档内容
1 我们 none r none
2 即将 none d none
3 以 6 p pob
4 昂扬 5 a rad
5 的 none u none
6 斗志 4 n att
7 迎来 1,2,3,10 v hed,sbv,adv,wp
8 新 9 a rad
9 的 none u none
10 一年 8 i vob