看了很久,看不出什么有关问题,帮忙看下
看了很久,看不出什么问题,帮忙看下
#include <stdio.h>
#include <stdlib.h>
main()
{
int a;
short s;
char c;
float f;
printf("please input int,short,char,float:");
scanf("%d,%d,%c,%f",&a,&s,&c,&f);
printf("a=%d,b=%d,c=%c,f=%f",a,s,c,f);
system("PAUSE");
}
代码输出为:
please input int,short,char,float:10,20,c,10.1
a=0,b=20,c=c,f=10.100000请按任意键继续. . .
很奇怪输出的a=0,代码编译用的dev c++。
------解决方案--------------------
#include <stdio.h>
#include <stdlib.h>
main()
{
int a;
short s;
char c;
float f;
printf("please input int,short,char,float:");
scanf("%d,%d,%c,%f",&a,&s,&c,&f);
printf("a=%d,b=%d,c=%c,f=%f",a,s,c,f);
system("PAUSE");
}
代码输出为:
please input int,short,char,float:10,20,c,10.1
a=0,b=20,c=c,f=10.100000请按任意键继续. . .
很奇怪输出的a=0,代码编译用的dev c++。
------解决方案--------------------
- C/C++ code
#include <stdio.h> #include <stdlib.h> main() { int a; short s; char c; float f; printf("please input int,short,char,float:"); scanf("%d,%d,%c,%f",&a,&s,&c,&f); printf("a=%d,b=%d,c=%c,f=%f",a,s,c,f); return 0; }
------解决方案--------------------
scanf("%d,%hd,%c,%f",&a,&s,&c,&f);
printf 同 scanf .
http://en.cppreference.com/w/cpp/io/c/fprintf
------解决方案--------------------
刚才我错了、、我在VS里调试正常、、但是在dev中 跟你的一样、、不晓得。等待解释
------解决方案--------------------