0

is it possible to make scanf not go into a newline after printf?

#include <stdio.h>
#include <conio.h>

int main(){
	int a;
	
	scanf("%d",&a); 
	printf ("%d",a);
	getch();
	
}

output(suppose a is 5) :

5
5

i want to print them in the same line like this

5 5

how do i do that?

5
Contributors
5
Replies
7
Views
5 Years
Discussion Span
Last Post by DJSAN10
0

I doubt there's a way of doing that because the new line character (ENTER) is what alerts the program that you are finished inputting your value.

0

I am not sure of this. But see if you can use the following somewhere

scanf("%[^\n]");

This code skips new line

0

I am not sure of this. But see if you can use the following somewhere

scanf("%[^\n]");

This code skips new line

Actually, it expects a single character that isn't a newline. Skipping a newline would look like this:

scanf("%*[\n]");

However, that doesn't accomplish what the OP wanted, which is accepting newlines without echoing them.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.