The program doesn't stop on scanf("%c", &ch) line, why?

c

Solution

Let's say you input 2 when you're reading for num. The actual input stream will be 2\n (\n is the newline character). 2 goes into the num, and there remains \n, which goes into ch. To avoid this, add a whitespace in format specifier.

scanf(" %c", &ch); 

This will ignore any whitespaces, newlines or tabs.

Problem

the program doesnt stop on scanf("%c", &ch) line. why does it happens sombody can please explain this to me ``` #include<stdlib.h> #include<stdio.h> struct list { char val; struct list * next; }; typedef struct list item; void main() { char ch; int num; printf("Enter [1] if you want to use linked list or [2] for realloc\n"); scanf("%d", &num); if(num == 2) { scanf("%c", &ch); printf("%c", ch); } } ```

Original source

Related problems