VC编程,C语言,scanf,printf问题
前面有定义结构体
struct student
{
int num;
char name[10];
int score[3];
};
以下是用3种情况输入一个学生的信息:
第一种:for(i=0;i<1;i++) //name放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%d,%d,%d,%s",&a[i].num,&a[i].score[0],&a[i].score[1],&a[i].score[2],a[i].name);
}
第二种:for(i=0;i<1;i++) //name不放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%s",&a[i].num,a[i].name);
scanf("%d",&a[i].score[0]);
scanf("%d",&a[i].score[1]);
scanf("%d",&a[i].score[2]);
}
第三种:for(i=0;i<1;i++) //name不放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%s,%d,%d,%d",&a[i].num,a[i].name,&a[i].score[0],&a[i].score[0],&a[i].score[0]);
}
打印的话都是用这个语句:for(i=0;i<1;i++)
{
printf("\n输出上面的信息:");
printf("%d,%s,%d,%d,%d",a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);
}
三种方法分别对应的输出显示情况如下:



但是我最想用的第3种方法,但是后面乱码,请问怎么回事?我猜是scanf的回车键结束引起的,但是不知道它内部怎么读数据的?有大神不?
struct student
{
int num;
char name[10];
int score[3];
};
以下是用3种情况输入一个学生的信息:
第一种:for(i=0;i<1;i++) //name放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%d,%d,%d,%s",&a[i].num,&a[i].score[0],&a[i].score[1],&a[i].score[2],a[i].name);
}
第二种:for(i=0;i<1;i++) //name不放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%s",&a[i].num,a[i].name);
scanf("%d",&a[i].score[0]);
scanf("%d",&a[i].score[1]);
scanf("%d",&a[i].score[2]);
}
第三种:for(i=0;i<1;i++) //name不放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%s,%d,%d,%d",&a[i].num,a[i].name,&a[i].score[0],&a[i].score[0],&a[i].score[0]);
}
打印的话都是用这个语句:for(i=0;i<1;i++)
{
printf("\n输出上面的信息:");
printf("%d,%s,%d,%d,%d",a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);
}
三种方法分别对应的输出显示情况如下:



但是我最想用的第3种方法,但是后面乱码,请问怎么回事?我猜是scanf的回车键结束引起的,但是不知道它内部怎么读数据的?有大神不?
...全文
相关推荐
程序设计技术实验报告.doc
通过这个实验,学生不仅能够巩固C语言的基础知识,还能提升他们在实际编程中解决输入输出问题的能力。
c语言实验选择结构程序设计整理.pdf
**熟悉VC6.0编程环境**:Visual C++ 6.0是一个经典的C/C++集成开发环境,用于编写、编译和调试C语言程序。理解其界面和基本操作对于编写和测试C程序至关重要。2.
C语言内涵教程(第二版).ppt
通过不断的上机实践和理解C语言的基本语法,初学者可以逐步掌握编程技巧,并能熟练地运用C语言解决问题。
C语言实验二选择结构程序设计.pdf
总结,本实验旨在通过实践加强学生对C语言中选择结构的理解,通过编写和调试程序,提高他们解决问题的能力。同时,这也是对逻辑思维和编程技巧的训练,有助于培养良好的编程习惯。
算10000以内数阶乘的C语言程序
标签中的“C,C++,VC,MFC”分别代表了:1. C:C语言,一种广泛使用的面向过程的编程语言。2. C++:C语言的超集,支持面向对象编程,具有更高级的功能和库。3.


