📄 13_9.cpp
字号:
#include<stdio.h>
#include<process.h>
#include<conio.h>
#define SIZE 2
typedef struct
{
char name[31];
int no;
int age;
char addr[31];
} Student;
Student student_list1[SIZE], student_list2[SIZE];
void main()
{
FILE *fp;
int i;
if((fp=fopen("d:\\student_list.dat","wb+"))==NULL)
{
printf("Cannot open file strike any key exit!");
getch();
exit(1);
}
printf("\ninput data(name, no, age, address)\n");
for(i=0; i<SIZE; i++){
scanf("%s%d%d%s", &student_list1[i].name, &student_list1[i].no,
&student_list1[i].age, &student_list1[i].addr);
}
if(SIZE != fwrite(student_list1, sizeof(Student), SIZE, fp) )
{
printf("write error!");
exit(1);
}
rewind(fp);
if(SIZE != fread(student_list2, sizeof(Student), SIZE, fp) )
{
printf("read error!");
exit(1);
}
printf("\n\nname number age address\n");
printf( "______________________________ ______ ___ ______________________________\n");
for(i=0;i<SIZE;i++)
{
printf("%-30s %-6d %-3d %-30s\n",student_list2[i].name,student_list2[i].no, /*打印*/
student_list2[i].age, student_list2[i].addr);
}
fclose(fp);
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -