Is there any way to use printf & scanf in one single line in C? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Is there any way to use printf & scanf in one single line in C?

That point suddenly came into my mind. I want to use both of them in single line .For e.g.Normally All we do is this printf("Enter no."); scanf("%d",&a); //i want to use scanf in printf line. likee(not working code but i think it'll make u clear what I'm talking about) printf scanf("Enter no","%d",&a);

24th Feb 2022, 3:06 AM
dead falcon
3 Answers
+ 3
⛔⛔⛔de@d falcon❌ You can do like that but result will be always 1 because scanf function returns 1 printf ("%d", scanf("%d", &a)); //This will always print 1 scanf function doesn't return input value
24th Feb 2022, 3:51 AM
A͢J
A͢J - avatar
+ 3
You could write your own function, take the print message and the input type, make the return send back the scanf input. Maybe a void pointer function that checks if %d or %s gets sent to the function, then returns the correct data type? I'm sure there will be guidelines for creating functions that you intend to publish....
24th Feb 2022, 3:55 AM
HungryTradie
HungryTradie - avatar
0
No error handling, no beautification, not really anything I can be proud of, but prinput seems to work for strings. https://code.sololearn.com/cswGeT0Y7MO9/?ref=app
1st Mar 2022, 5:48 AM
HungryTradie
HungryTradie - avatar