Home Segments Index Top Previous Next

516: Mainline

Although the gets function generally returns a pointer to the first character in the character array, should you redirect input to a file, and should the gets function encounter the end of a file, it returns the null pointer, which is a pointer to address zero.

You frequently see the null pointer written as NULL, a macro symbol. By using NULL, instead of 0, you identify those places where 0 is used as a special pointer, thereby increasing program clarity.

Thus, the following expression tests the result of a call to gets to ensure that the end of a file has not yet been encountered:

gets (input_buffer) != NULL