我制作了文本文件 studenti.txt
- Gatis Lietnieks 15.06.1993 v
- Vizma Kalesnica 20.08.1991 年代
- Katrina Sabone 06.12.1992 年代
- Haralds Burkovskis 01.02.1989 v
- Jezups Martinovs 02.05.1990 v
- Vizma Zigurde 16.09.1988 年代
- 斯塔西娅·巴罗德 12.12.1993 年代
- Jānis Bērziņš 13.03.1992 v
- Zigurds Ritms 16.05.1990 v
- Pauls Zirdzins 12.11.1989 v
- 赞恩·斯卡布尔 28.12.1990 年代
- 艾加布勒 11.08.1993 年代
- 安德烈斯·福姆金斯 11.06.1989 v
- Maikls Dzordans 08.01.1988 v
我想读取文件并将其打印在 c 程序输出中。
我的代码是:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <windows.h>
#include <ctype.h>
#define N 16
int main()
{
FILE *fails_st;
struct date
{ int da_year;
int da_month;
int da_day;
};
struct studenti
{
int Nr;
char name[25];
char surname[25];
struct date dzd;
char dzimums[1];
} students[N];
int i, j;
system("cls");
fails_st = fopen("studenti.txt", "r");
for(i=0; i<N; i++)
{
fscanf(fails_st, "%d", &students[i].Nr);
fgets(students[i].name, sizeof students[i].name, fails_st);
fgets(students[i].surname, sizeof students[i].surname, fails_st);
fscanf(fails_st, "%d", &students[i].dzd.da_day);
fscanf(fails_st, "%d", &students[i].dzd.da_month);
fscanf(fails_st, "%d", &students[i].dzd.da_year);
fgets(students[i].dzimums, sizeof students[i].dzimums, fails_st);
}
fclose(fails_st);
system("cls");
printf("Student list\n");
for(i=0; i<N; i++)
printf("%d%s%s%d%d%d%s\n", students[i].Nr,
students[i].name, students[i].surname,
students[i].dzd.da_day,students[i].dzd.da_month,students[i].dzd.da_year,students[i].dzimums);
getch();
return 0;
}
但是程序输出是这样的,我想知道为什么
Student list
1. Gatis Lietnieks 15.06.1993 v
202011158932
0. Vizma Kalesnica 20.08.1991 s
342685996
2130567168. Katrina Sabone 06.12.1992 s
48739784137
0. Haralds Burkovskis 01.02.1989 v
587162880
0. Jezups Martinovs 02.05.1990 v
626862441
0. Vizma Zigurde 16.09.1988 s
787397928
0. Stasija Balode 12.12.1993 s
987397848739786
0. JŌnis Bńrzi“ 13.03.1992 v
1041984004198400
4096. Zigurds Ritms 16.05.1990 v
1126864728741408
....
.................................
.................................
.................................