why does gets work faster than scanf? http://www.codechef.com/FEB14/status/LCPESY,raul1rnjn535_3 .with gets i got the output in 0.00 seconds & with scanf i got the output in 0.01 seconds. In another problem the time got reduced from 0.09 deconds to 0.02 seconds when i used gets instead of scanf…
btw, pls dont share ongoing contest answers or submissions
the link that u provided does not answer my question…it only says how to use gets with scanf?i want to know why gets works faster than scanf…I will be careful about not sharing the contest submissions during the contest from now on…
bro, dont insist on gets(), because gets() is not safe. 0.07 sec difference is not a big deal. so use safer one - scanf()
i know that it is not safe & i use scanf…i just want to know why it works faster than scanf?
not sure, but is it because
gets() function acts
getchar() somewhat alike? if yes, then:
getchar() has no parameters. Every
time you call it, it reads the next
character of input and returns it to
you. The function returns an int,
being the ASCII code of the relevant
character, but you can assign the
result to a char variable if you want.
gets() doesnt heed whitespace or whatsoever except newline("\n") and consumes everything till it encounters newline indicator or EOF. on the other hand,
scanf() reads till whitespace or newline or just till the end of string.
gets() swallow whole line not just string.
I’m NOT SURE. anyway, may be this link gonna help you: http://stackoverflow.com/questions/4346598/gets-function-in-c