3 ms·
Hence advanced bait. printf() is called in a while loop, so it is hardly a single call.
by qllp100 6y ago
Hence advanced bait. printf() is called in a while loop, so it is hardly a single call.
- taspeotis 6y agoI don’t want to jump on the title hate bandwagon - what the author has done is definitely creative and clever and this discussion detracts from it - but it also uses scanf.
- quietbritishjim 6y agoWhere? int main() { while(*d) printf(fmt, arg); }
- shawnz 6y agoOn line 57: https://github.com/carlini/printf-tac-toe/blob/master/printtt.c#L57 https://github.com/carlini/printf-tac-toe/blob/master/printt...
- quietbritishjim 6y agoAh, well spotted, thanks. I didn't think it was fair to call the title click bait just because it used a while loop to drive the calls to printf, but also including a scanf call is definitely not in the same spirit.
- hibbelig 6y agoAlas, it's technically difficult to get input from the user using printf.
- quietbritishjim 6y agoHmm that is a good point :-)
- Someone 6y agoIf you’re willing to lose almost all portability, I think you could read a value from an I/O port, pass that to printf, use that as the field width for a string to print, count the character length of the resulting string using %n to move it into a variable, and then backspace over that to prevent the output from dirtying your output. You could only use the results in a subsequent call to printf, though. Of course, just hiding an assignment in a printf argument would be much easier, but wouldn’t be fun. Of course, that would lose lots and lots of portability, and you could, likely, only get it to work on systems that don’t do memory protection between processes, and then, not all of them. I guess it would not be very hard to use this trick to have printf read joysticks on many micro’s from the 1980’s.
- saagarjha 6y agoIn that case it might just be easier to ROP your way to scanf.