FrySnow
FrySnow
2019-10-15 16:40
采纳率: 100%
浏览 681

c语言新手,scanf函数输入数据总是显示0.0000000

#include
int main()
{
int a,b;
float x,y;
char c1,c2;
scanf("%d,%d",&a,&b);
scanf("%f,%f",&x,&y);
scanf("%c,%c",c1,c2);
printf("a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%c",a,b,x,y,c1,c2);
return 0;
}
就是如图的程序,我在输入数据后(3,7,70,80,A,B)后,除了a,b正常,x和y一直输出0.000000,而c1和c2一直是c1=,,c2=e
请问各位这是哪里出了问题啊?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • qq_31762199
    豆丷 2019-10-15 16:56
    已采纳

    逗号没匹配,前两个scanf中间没有逗号,而你输入了逗号,所以第二个scanf把逗号给了x,
    char类型没有使用&取地址

    int a, b;
        float x, y;
        char c1, c2;
        scanf("%d,%d,%f,%f,%c,%c", &a, &b, &x, &y, &c1, &c2);
    
        printf("a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%c", a, b, x, y, c1, c2);
        return 0;
    
    点赞 评论
  • qtchen_1988
    qtchen_1988 2019-10-15 17:06
    #include<stdio.h>
    #include<stdlib.h>
    
    int main()
    {
        int a,b;
        float x,y;
        char c1,c2;
    
        char t;
        scanf("%d,%d",&a,&b);
        t = getchar();
        printf("t=%d  %c\n",t,t);
        scanf("%f,%f",&x,&y);
        t = getchar();
        printf("t=%d  %c\n",t,t);
        scanf("%c,%c",&c1,&c2);
    
        printf("a=%d,b=%d,x=%f,y=%f,c1=%c,c2=%c",a,b,x,y,c1,c2);
        return 0;
    }
    
    
    点赞 评论

相关推荐