>Why must pt be a pointer?
Because gets returns a pointer to the first element of the buffer that you pass to it as an argument. It makes for more convenient code. You can do this if you really want to:
Code:
puts ( gets ( buffer ) );
Instead of
Code:
gets ( buffer );
puts ( buffer );
Or, for a more practical reason since gets can return NULL if the input fails in some way:
Code:
if ( gets ( buffer ) != NULL ) {
/* Use buffer */
}
else {
perror ( "Input error" );
bail();
}
Also, if pt = gets(buffer) - is that checking the return value of gets, or would that return what they actually typed?
Both and neither...sort of. If gets fails then it returns NULL, so pt might not be what the user typed. On the other hand, if successful, gets will return a pointer to the buffer, so pt will point to what the user typed.
Of course, you shouldn't use gets because there's no way to make it safe from buffer overflow errors. However, your question is also relevant to fgets, which is the safe alternative to gets.