繁体   English   中英

我们可以调用 Switch() 的“案例”吗? 代码中任何其他地方的语句 [C 程序设计语言]

[英]Can we call a 'Case' of Switch(); statement from anywhere else in the code [C Programming Language]

这是一个演示代码,用于解释我实际在寻找什么

我想从 C 语言代码中的其他地方调用“switch”的“case”-语句。

这是源代码:

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>

char a;

int main()
{
    printf("Enter a number: ");
    scanf("%c", &a);
    switch(a){
    case 'a':
        printf("This is for A & C");
        break;
    case 'b':
        printf("This is for only B");
        break;
    case  'c':
        // Here i want to call "case 'a':"
    goto case 'a';

        // how can a call another case here?
        
        break;
    default:
        printf("Default");
        break;
    }
    getch();
    return 0;
}

谢谢是提前:D

您需要所谓的“跌倒”案例:

所以而不是这个:

case 'a':
    printf("This is for A & C");
    break;
case 'b':
    printf("This is for only B");
    break;
case  'c':
    // Here i want to call "case 'a':"

写这个:

case 'a':
case 'c':
    printf("This is for A or C");
    break;

case 'b':
    printf("This is for only B");
    break;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM