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?

No. In order to read the 5 you have to hit ENTER.

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.

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

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

This code skips new line

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.

@narue ok thank you for the correction

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.