下面语C言怎样修改(修改后尽量保持原来的编程思想)

来源:百度知道 编辑:UC知道 时间:2024/05/22 01:06:54
#include<stdio.h>
#include<malloc.h>

struct stu{
int num;
char name[20];
struct stu *next;
};

void main()
{
FILE *fp;
struct stu *head,*p1,*p2;
int i=0,n;
char b;
printf("请输入学生总数!\n");
scanf("%d",&n);
start:
p1=(struct stu*)malloc(sizeof(struct stu));
printf("请输入序号,姓名:\n");
scanf("%d,%s",&p1->num,p1->name);
if(!i)
{head=p1;p1=head->next;}
else {p2=p1;p1=p2->next;}
i++;
if(i<n)goto start;
p1=head;

fp=fopen("xyj.txt","w");
if(fwrite(p1,sizeof(struct stu),1,fp)!=1)
{
printf("file write failed!\n");
goto end;
}
printf("Will you add the formation\n to the file of \"xyj.txt\"?[Y/N]\n");
scanf("%c",&b);
if(b=='y'||b=='Y')
for(i=0;i<n;

#include<stdio.h>
#include<malloc.h>

struct stu{
int num;
char name[20];
struct stu *next;
};

void main()
{
FILE *fp;
struct stu *head,**p1,*p2;
int i=0,n;
char b;
printf("请输入学生总数!\n");
scanf("%d",&n);
p1=&head;
start:
*p1=(struct stu*)malloc(sizeof(struct stu));
printf("请输入序号,姓名:\n");
scanf("%d,%s",&(*p1)->num,(*p1)->name);
if(!i)
{head=*p1;p1=&(head->next);}
else {p1=&(*p1)->next;}
i++;
if(i<n)goto start;
p2=head;

fp=fopen("xyj.txt","w");
if(fp==NULL)
{
printf("file write failed!\n");
goto end;
}
printf("Will you add the formation\n to the file of \"xyj.txt\"?[Y/N]\n");
scanf("\n%c",&b);

if(b=='y'