📄 1.cpp
字号:
/*函数功能:录入学生信息*/
struct student *inputmessages()
{
struct student *another,*tail,*head;
FILE *fp; /*文件指针*/
char filename[10]; /*文件名*/
int i,n;
printf("input the name of file:\n"); /*输入文件名*/
scanf("%s",filename);
if((fp=fopen(filename,"w"))==NULL) /*建立并打开新文件*/
{
printf("Can not open file.\n");
exit(0); /*终止程序*/
}
printf("input the number of student:\n"); /*输入学生的个数*/
scanf("%d",&n);
for(i=0;i<n;i++) /*建立学生的链表*/
{
another=(struct student *)malloc(sizeof(struct student));
printf("Input the num name year sex birthday \
address phone mail of student %d:\n",i+1);
scanf("%s %s %d %c %d %s %s %s",another->num,another->name,\
another->year,another->sex,another->birthday,\
another->address,another->phone,another->mail);
if(i==0)
head=another;
else tail->next=another;
tail=another;
}
another->next=NULL;
tail=head;
while(tail!=NULL) /*将学生信息写入到文件中*/
{
fprintf(fp,"%s %s %d %c %d %s %s %s",tail->num,tail->name,\
tail->year,tail->sex,tail->birthday,\
tail->address,tail->phone,tail->mail);
tail=tail->next;
}
fclose(fp); /*关闭文件*/
return(head);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -