c语言循环输入的时候,第一组数据和第二组数据一起输入了,但是最终显示出的数据顺序是对的,求大神指教!!!
输出结果如下:

代码如下:
#include<stdio.h>
#include<string.h>
struct students
{
char name[10];
char number[10];
int score;
struct students *next;
};
int main()
{
int i,j,k;
struct students stu[5],*head,*p;
char n[10],no[10];
for(i=0;i<5;i++)
{
printf("input the information of %dth student:\n",i+1);
scanf("%s%s%d\n",n,no,&stu[i].score);
strcpy(stu[i].name,n);
strcpy(stu[i].number,no);
}
head=&stu[0];
stu[4].next=NULL;
for(i=0;i<4;i++)
{
stu[i].next=&stu[i+1];
}
p=head;
printf("students list:\n");
while(p!=NULL)
{
printf("%s\t%s\t%d\n",p->name,p->number,p->score);
p=p->next;
}
}

代码如下:
#include<stdio.h>
#include<string.h>
struct students
{
char name[10];
char number[10];
int score;
struct students *next;
};
int main()
{
int i,j,k;
struct students stu[5],*head,*p;
char n[10],no[10];
for(i=0;i<5;i++)
{
printf("input the information of %dth student:\n",i+1);
scanf("%s%s%d\n",n,no,&stu[i].score);
strcpy(stu[i].name,n);
strcpy(stu[i].number,no);
}
head=&stu[0];
stu[4].next=NULL;
for(i=0;i<4;i++)
{
stu[i].next=&stu[i+1];
}
p=head;
printf("students list:\n");
while(p!=NULL)
{
printf("%s\t%s\t%d\n",p->name,p->number,p->score);
p=p->next;
}
}
...全文
相关推荐
数据结构(C语言版)——循环顺序队列(代码版)
数据结构(C语言版)——循环顺序队列(代码版)里面包含C文件和exe文件。基本操作为:1:初始化循环顺序队列2:销毁循环顺序队列3:清空循环顺序队列4:循环顺序队列是否为空5:返回循环顺序队列头元素6:元素入队7:元素出队8:当前循环顺序队列长度
c语言求余数的实例讲解
c语言如何求余数? C语言中求余数直接用双目运算符%,如求a除以b的余数可表示为a%b 注意:C语言中的运算符%的两个操作数必须为整形,不能为浮点型或其他结构体类型,否则编译器会提示错误。 示例代码: #include int main() { int a=5, b=3, c; c=a%b; //将a除以b的余数赋值给c printf("%d",c); return 0; } /* 输出:2 */ 知识点补充: C语言求余数问题 C语言里对于有一些符号是不能直接输出的,因为被C语言占用了。所以有一些符号是需要特殊的方式才能输出的。比如你说的%号,%
C语言实现顺序表的顺序查找和折半查找
主要为大家详细介绍了C语言实现顺序表的顺序查找和折半查找,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
c语言实现矩阵求逆程序
c实现矩阵求逆程序。希望对大家有所帮助。
求两点距离(C语言)
程序实现求两点距离,C语言入门程序,C语言课程数字计算类小练习。


