我是靠谱客的博主 专注大地,这篇文章主要介绍c语言实现读取txt文件内容到结构体数组中,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h> #include <stdlib.h> #define N 10 typedef struct { char work_ID[5]; char name[20]; char phone_nu[12]; }student; int main(int argc, char *argv[]) { student st[N]; FILE *fp; int i; int count; if(argc != 2) { fprintf(stderr, "usage:argc is not twon"); exit(1); } if((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "Can't open the %s", argv[1]); } for(i = 0; i < N; i++) { if((fscanf(fp, "%s%s%s", st[i].work_ID, st[i].name, st[i].phone_nu)) != 3) { break; } } count = i; //display printf("the ture count is %dn",count); for(i = 0; i < count; i++) { printf("%st%st%sn", st[i].work_ID, st[i].name, st[i].phone_nu); } return 0; }


 

最后

以上就是专注大地最近收集整理的关于c语言实现读取txt文件内容到结构体数组中的全部内容,更多相关c语言实现读取txt文件内容到结构体数组中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(66)

评论列表共有 0 条评论

立即
投稿
返回
顶部