void print(SI*head)/*把数据显示到屏幕上*/
{
SI*p;
char ch;
int i;
p=head;
if(head!=NULL)/*判断是否有数据*/
{printf("Name\tTelephone\t***\tAge\tBirthday\tDormitory\n");
while(p->next!=NULL)
{for(i=0;i<5;i++)/*用来限制每次只输出5个信息*/
{printf("%-s\t%-10s\t%-s\t%-10s\t%-s\n",p->name,p->phone,p->age,p->birthday,p->dormitory);
p=p->next;
if(p==NULL){goto en*;}/*检查*是否为空,如果为空,则跳到本函数最尾,输出这是最后一页*/
}
*rintf("go on(Y\\N):");/*询问用户是否继续查看*/
getchar();
ch=getchar();
if(ch=='Y'||ch=='y')/*判断是不是继续显示没有显示完的信息*/
{clrscr();
mainmenu_limit();/*由于是假的分屏显示,所以每次清屏,都必须添加菜单*/
printf("Name\tTelephone\t***\tAge\tBirthday\tDormitory\n");}
else{break;}}
/*判断数据是否读完*/
}
end:;
printf("The last page!");
}
与上次的代码相比,本代码增加了判断P是否为空,这样就可以解决上次代码到了最后一页,或者记录不是为5的整数而出错的问题.
{
SI*p;
char ch;
int i;
p=head;
if(head!=NULL)/*判断是否有数据*/
{printf("Name\tTelephone\t***\tAge\tBirthday\tDormitory\n");
while(p->next!=NULL)
{for(i=0;i<5;i++)/*用来限制每次只输出5个信息*/
{printf("%-s\t%-10s\t%-s\t%-10s\t%-s\n",p->name,p->phone,p->age,p->birthday,p->dormitory);
p=p->next;
if(p==NULL){goto en*;}/*检查*是否为空,如果为空,则跳到本函数最尾,输出这是最后一页*/
}
*rintf("go on(Y\\N):");/*询问用户是否继续查看*/
getchar();
ch=getchar();
if(ch=='Y'||ch=='y')/*判断是不是继续显示没有显示完的信息*/
{clrscr();
mainmenu_limit();/*由于是假的分屏显示,所以每次清屏,都必须添加菜单*/
printf("Name\tTelephone\t***\tAge\tBirthday\tDormitory\n");}
else{break;}}
/*判断数据是否读完*/
}
end:;
printf("The last page!");
}
与上次的代码相比,本代码增加了判断P是否为空,这样就可以解决上次代码到了最后一页,或者记录不是为5的整数而出错的问题.
转载于:https://blog.51cto.com/songcz/153973