gets() in gcc.

plz tell me whether gets() works in gcc or not…bcz it was giving WA when i was using gets() in ques RRCODE…and AC when used scanf()

gets() works in gcc very well.

The reason why you got WA is because, after you read the three integers, the new line character is still present in the input buffer, and gets simply reads this newline character to return an empty string as the “operator”. However, scanf ignores whitespaces, and so, it reads the next consecutive set of non-whitespace characters to give you right answer.

To use gets(), you can add a dummy gets immediately before the actual gets, to consume the extra newline. Or, you can just put a newline or space at the end of your scanf, like scanf("%d%d%d\n", &n, &k, &answer);

2 Likes

but for this i used getchar() before gets() and pgm was running fine on dev as well as on codeblocks…and was giving compile error on gcc…

//