how to use gets after scanf 1

how to use gets after scanf

scanf("%d",num);
int c=getchar();
gets(str);

Here is what the above code is Doing:
1. It is taking an integer input from the user.
2. It is taking a character input from the user.
3. It is taking a string input from the user.

Now, the problem is that the second scanf() statement is taking the newline character as input.

So, the third gets() statement is taking the newline character as input.

To avoid this, we can use the getchar() statement.

The getchar() statement takes the newline character as input and does not store it in any variable.

So, the third gets() statement will take the string input from the user.

Similar Posts