The Single UNIX ® Specification, Version 2
Copyright © 1997 The Open Group


gets - get a string from a stdin stream


#include <stdio.h>

char *gets(char *s);


The gets() function reads bytes from the standard input stream, stdin, into the array pointed to by s, until a newline is read or an end-of-file condition is encountered. Any newline is discarded and a null byte is placed immediately after the last byte read into the array.

The gets() function may mark the st_atime field of the file associated with stream for update. The st_atime field will be marked for update by the first successful execution of fgetc(), fgets(), fread(), getc(), getchar(), gets(), fscanf() or scanf() using stream that returns data not supplied by a prior call to ungetc().


Upon successful completion, gets() returns s. If the stream is at end-of-file, the end-of-file indicator for the stream is set and gets() returns a null pointer. If a read error occurs, the error indicator for the stream is set, gets() returns a null pointer and sets errno to indicate the error.


Refer to fgetc().




Reading a line that overflows the array pointed to by s causes undefined results. The use of fgets() is recommended.




feof(), ferror(), fgets(), <stdio.h>.


Derived from Issue 1 of the SVID.

UNIX ® is a registered Trademark of The Open Group.
Copyright © 1997 The Open Group
[ Main Index | XSH | XCU | XBD | XCURSES | XNS ]