#include <stdio.h>
int main()
{
char str[100], search[100];
printf("Enter a string ");
scanf("%[^\n]s",str);
printf("\n Enter search substring ");
scanf("%[^\n]s",search);
}
When I run the above code, the first scanf() does execute and takes user input. However, it skips over the second scanf() and ends the program.
I think this happens because the second scanf() finds \n in the buffer (from previous input) and stops. What can I do to correct this behaviour?