关于一个共用体字符串输入的问题

# include <stdio.h>


# include <conio.h>


# include <stdlib.h>






union computerInfo


{


    char band[20];


    float  price;


};






void main(void)


{


    union computerInfo comp1 = {"Asus X80"};


    //union computerInfo comp1 ;


    int type = 0;






    puts("Please input the type of the computers:");


    scanf("%d",&type);






    switch(type)


    {


        case 0:


        puts("please input the band of the computer");


        scanf("%s",&comp1.band)(1);


        //scanf("%s",comp1.band)(2);


        //gets(&comp1.band)(3);


        //gets(comp1.band)(4);
问题出现在这里: 在这里(1)和(2)两个表达式都是可以执行的,为什么呢?按道理来说,(1)是不对;(2)是正确的,但是不能输入空格隔开的单词;(3)是错的,编译的时候就会通知有错误;(4)编译可以通过,但是程序执行的时候,不需要输入,直接就略过了输入品牌的这一步为什么?   
        printf("the type of the computer is: %s\n",comp1.band);


        break;


    case 1:


        puts("please input the price of the computer");


        scanf("%f",&comp1.price);


        printf("The price of the computer is %f\n",comp1.price);


        break;


    default:


        puts("The input type is wrong!");


        break;


    }
}
问题就在上面,求大侠解答。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值