#include
//定义结构体Sales_record
struct Sales_record
{
char c[5];
char n[11];
char s[20];
int p;
int q;
struct Sales_record *next;
};
void main()
{
FILE *filep;
struct Sales_record *head,*dp,*cp;
int n=0,i=0,x=0;
scanf("%d%d",&n,&i);
/*
* 此处为补充的内容
* 可以令程序避免出现一个操作错误
* while(i* {
* printf("你输入了一个不正确的参数,请重新输入:");
* scanf("%d%d",&n,&i);
* }
*/
filep=fopen("out.dat","a+");
//获取第一条记录,并写入out.dat文件
dp=(struct Sales_record *)malloc(sizeof(struct Sales_record));
scanf("%s%s%s%d%d",&dp->c,&dp->n,&dp->s,&dp->p,&dp->q);
fprintf(filep,"%s %s %s %d %d\n",dp->c,dp->n,dp->s,dp->p,dp->q);
dp->next=NULL;
head=dp;
//获取剩余记录,并写入out.dat文件
for(x=0;x{
cp=(struct Sales_record *)malloc(sizeof(struct Sales_record));
scanf("%s%s%s%d%d",&cp->c,&cp->n,&cp->s,&cp->p,&cp->q);
fprintf(filep,"%s %s %s %d %d\n",cp->c,cp->n,cp->s,cp->p,cp->q);
cp->next=NULL;
dp->next=cp,dp=cp;
}
//输出第N条记录
dp=head;
for(x=1;x<=i;x=x+1)
{
if(x==i)
{
printf("%s %s %s %d %d\n",dp->c,dp->n,dp->s,dp->p,dp->q);
}
else
{
dp=dp->next;
}
}
}
看不清啊,再弄清楚一点吧