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);
3 Antworten
+ 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
+ 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....
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