0
void xyz()
{
    char input_new;
    printf("enter D or F:");
    scanf("%c",&input_new);
    switch(input_new)
    {
        case 'D':
            //Code
            break;
        case 'F':
            //code
            break;
    }
}

int main()
{
    char input;
    printf("enter A or B:");
    scanf("%c",&input);
    switch(input)
    {
        case 'A':
            xyz();
        break;
        case 'B':
            abc();
        break;
    }
    return 0;
}

why this code is unable to execute the switch case of function xyz(). it is getting terminated after printing "Enter D or F". Somebody please help me.

Support Ukraine
  • 42,271
  • 4
  • 38
  • 63
  • Try this: `scanf("%c",...` -> `scanf(" %c",...` Notice the space before `%c` It removes all whitespaces including newline. – Support Ukraine Oct 14 '17 at 14:31
  • 1
    *Always* include a `default` case, if nothing else to report an error (and in your specific case printing the character you received). That would make it *very* easy to find out the problem. Or by stepping through the code in a debugger (which is really what you should have done first). – Some programmer dude Oct 14 '17 at 14:34
  • The program is terminating because you don't have defined abc(). – kunwar97 Oct 14 '17 at 15:25
  • This is just a reference code, i defined the abc() function in original code. – pratim mishra Oct 15 '17 at 10:12

0 Answers0