C - equivalent of .NET Console.ReadLine

SharpAffair picture SharpAffair · Mar 18, 2010 · Viewed 8.6k times · Source

I need to accomplish the same behavior as .NET Console.ReadLine function provides. The program execution should continue when the user pushes enter key.

The following code is not sufficient, as it requires additional input:

printf ("Press Enter to continue");
scanf ("%s",str); 

Any suggestions?

Answer

S.C. Madsen picture S.C. Madsen · Mar 18, 2010

You could use fgets(), like so:

#include <stdio.h>

fgets(buf, sizeof(buf), stdin);