Obtaining user input can be done in many surprisingly different ways. This code is somewhere in the middle: safer than
scanf("%s", text) , but not bulletproof. It is meant to be a simple but relatively safe demonstration.
mygetline reads user input from the
stdin into a string using
fgets . Then it attempts to remove a trailing newline that
fgets may leave in the string. It returns a pointer to the destination string.