#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
int intvar=0; //variable to store integer input
double decimalvar = 0; //variable to store double input
char string[30]; //arrary to store string
scanf("%d",&intvar); //scan for int input
scanf("%f",&decimalvar); //scan for double input
scanf("%[^\n]",string); //scan for a line input
printf("%d\n",intvar); //print int var
printf("%.1f\n",decimalvar);//print double var
printf("%s",string);//print string
return 0;
}
The program runs successfully, but it only takes two input. After entering the second input, the third scanf statement is skipped and the printf statements are executed. Why does this happen?