scanf后的printf都没用了
usrbin吧
全部回复
仅看楼主
level 6
流世逐遗 楼主
#include<stdio.h>
int main()
{
struct student
{
char name[20];
char sex[10];
int age;
int number;
float score;
}student1;
printf("enter the name\n");
scanf("%s",&student1.name);
printf("the sex\n");
scanf("%s",&student1.sex);
printf("the age\n");
scanf("%d",&student1.age);
printf("number\n");
scanf("%d",&student1.number);
printf("score\n");
scanf("%f",&student1.score);
printf("the student's message ");
printf("%s\n%s\n%d\n%d\n%f\n",student1.name,student1.sex,
student1.age,student1.number,student1.score);
getchar();
return 0;
}
代码有问题吗?输入完了以后直接黑框消失,试了几种都是scanf后tj了
@usrbin
@灌水四人组之蛋
@KeyTo9
@聿鬼
@铁砣陈
@岸边拾贝壳

2011年07月12日 01点07分 1
level 13
木问题,看输出信息
那是因为最后一个scanf后
getchar把你最后一个按键抓出来了,所以getchar停不下来然后return 0去了
您可以在return 0下断或者system("pause")来暂停程序
2011年07月12日 01点07分 2
level 6
流世逐遗 楼主
“getchar把你最后一个按键抓出来了”这是什么道理?[88]
“在return 0下断”是?[我错了]
2011年07月12日 01点07分 3
level 7
编译器要是VS的话,在return 0前面加一句system("pause")就行了。
2011年07月12日 01点07分 4
level 6
流世逐遗 楼主
还有定义结构变量时
struct 结构名 结构变量名
这样会提示出错
two or more data types in declaration of 变量名
2011年07月12日 01点07分 5
level 6
流世逐遗 楼主
dev也行[呵呵]
2011年07月12日 01点07分 6
level 11
说实话,我也不知道怎么办,我又不是高手……我通常都是用的system("pause")……
2011年07月12日 02点07分 7
level 13
回复:3楼
最后一个scanf时候你键盘送了\n\r (还是\r\n忘了),它们还留在键盘输入缓冲区
到你getchar时,由于键盘缓冲区还有内容,所以这个函数就读了出来,不作停留
您如果想用getchar暂停,那么在getchar之前用fflush(stdin)来清空键盘缓冲区,这样getchar才停下来等待键盘缓冲区的输入,即实现您期望的暂停
2011年07月12日 02点07分 8
level 11
回复8楼:
懂了…
2011年07月12日 02点07分 9
level 14
[打酱油]编译中有两个警告

2011年07月12日 02点07分 10
level 14
[打酱油]不过可以运行

2011年07月12日 02点07分 11
level 6
流世逐遗 楼主
好。。。但还是不会处理。。。
2011年07月12日 02点07分 12
level 6
流世逐遗 楼主
什么的警告?
2011年07月12日 02点07分 13
level 14
看10楼图片
2011年07月12日 02点07分 14
level 6
流世逐遗 楼主
看不懂啊。。。5楼的问题呢[揉脸]
2011年07月12日 02点07分 15
level 14
[汗]具体点
2011年07月12日 02点07分 16
level 13
同16楼,给码看看
2011年07月12日 02点07分 17
level 6
流世逐遗 楼主
1.arg不懂。。。
2.定义结构变量用 struct 结构名 结构变量名 会出错
在定义结构其后定义结构变量就不会出错(1楼那样)
2011年07月12日 02点07分 18
level 6
流世逐遗 楼主
#include<stdio.h>
#include<stdlib.h>
int main()
{
struct student
{
char name[20];
char sex[10];
int age;
int number;
float score;
}
struct student student1;
printf("enter the name\n");
scanf("%s",&student1.name);
printf("the sex\n");
scanf("%s",&student1.sex);
printf("the age\n");
scanf("%d",&student1.age);
printf("number\n");
scanf("%d",&student1.number);
printf("score\n");
scanf("%f",&student1.score);
printf("the student's message ");
printf("%s\n%s\n%d\n%d\n%f\n",student1.name,student1.sex,
student1.age,student1.number,student1.score);
system("pause");
return 0;
}

2011年07月12日 02点07分 19
level 14
struct student student1;前面的大括号后面少个;[汗]
2011年07月12日 03点07分 20
1 2 尾页