I have a c program where the user is asked to input numbers as data. How can I restrict the user inputs to number only and how to prevent the program from misbehaving if any special character or non integer input is given?
void insert(){
int data;
printf("ENTER DATA: ");
struct node *block = (struct node*)malloc(sizeof(struct node));
scanf("%d",&data);
block->data = data;
block->link = head;
head = block;
}
In the above function if the user enters any non integer character the programs just goes into infinite loop printing the print statement.