Q:

Linked list trouble

Does anyone know what might be the problem with the following code? When I run it, I get the following output:
Insert a value in the list: 1
Do you want to continue? y/N: 
 1 ->

The fact is that the do-while loop executes until the scanf("%c", &ch) statement, and then it jumps out (so I cannot provide any input for the ch variable). I tried debugging with GDB and I got some weird messages: 
GI___libc_malloc (bytes=16) at malloc.c:malloc.c: No such file or directory. 

Also, it says that the compiler couldn't find the vscanf.c file. Does anyone have an explanation for this strange behavior? Thanks! (The intention was to print the values of a singly linked list in reverse order.)
#include <stdio.h>
#include <stdlib.h>

struct node{
    int info;
    struct node* next;
};

struct node* head = 0;

void add_node(int value){

     struct node* current = malloc(sizeof(struct node));
     current->info = value;
     current->next = head;
     head = current;
 }

void print_node(struct node* head){

     while(head){

          printf(" %d -> ", head->info);
          head = head->next;
     }

     printf("\n");
 }

int main(void){

    int val;
    char ch;

    do {

       printf("Insert a value in the list: ");
       scanf("%d", &val);
       add_node(val);
       printf("Do you want to continue? y/N: ");
       scanf("%c", &ch);

    } while(ch == 'y' || ch == 'Y');

    printf("\n");
    print_node(head);
    return 0;
 }

A:

The problem you are encountering is because the  once you type a value for val and then press enter , then \n still remains in the input buffer . Hence , the next scanf assumes  that \n which is still in the input buffer is its input , and consumes it and then loop exits .
Other Solutions  :- 
1) scanf("%d%*c",&val);
This would assign the first input character to val and then anything after that would be eaten up . Hence , the \n would not go into the next scanf 
2) scanf("%[^\n]%*c",&val);
This would assign the anything  to the val except \n and then \n would be eaten up .

