Switch statement using string on an array

前端 未结 8 1511
礼貌的吻别
礼貌的吻别 2021-01-13 06:28
#include

int main(){

    char name[20];

    printf(\"enter a name \");
    scanf(\"%s\",name);
    switch(name[20]){
        case \"kevin\" : 
             


        
8条回答
  •  醉酒成梦
    2021-01-13 07:05

    Remember the rules while using switch statements.

    Switch constraints

    1. The controlling expression of a switch statement must have "integer type".

    2. The expression of each case label shall be an integer constant expression and no two of the case constant expressions in the same switch statement shall have the same value after conversion. There may be at most one default label in a switch statement.

    3. Any enclosed switch statement may have a default label or case constant expressions with values that duplicate case constant expressions in the enclosing switch statement.

提交回复
热议问题