A C Code, getting a string using gets();
last night one of my friend showed me a C code and told me that he was unable to get the string input using gets(); I am posting the code here.
printf("Please enter your name: ");
Now, he was very confused that why this simple code is not working. I asked him to put fflush() before calling to gets(). He did it and the code worked fine. Do you get the reason?
The printf does not flush the memory and when you call the gets() it use the buffer characters already in memory buffer thus returning empty string.