gets()
QNX SDP8.0C Library ReferenceAPIDeveloper
Get a string of characters from standard input
Synopsis:
#include <stdio.h>
char *gets( char *buf );
Arguments:
- buf
- A buffer where the function can store the string.
Library:
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
Description:
The gets() function gets a string of characters from the stdin stream, and stores them in the array pointed to by buf until end-of-file is encountered or a newline character is read. Any newline character is discarded, and the string is NUL-terminated.
Note:
You should use
fgets() instead of
gets(); gets() happily overflows the
buf array if a newline character isn't read from
stdin before the end of the array is reached.
The gets() function is similar to fgets(), except that gets() operates with stdin, has no size argument, and replaces a newline character with the NUL character.
Returns:
- If successful, gets() returns buf.
- If the end-of-file indictor for the stream is set, or the stream is at the end of the file, gets() sets the end-of-file indicator and returns NULL.
- If an error occurred, gets() sets the error indicator, sets errno, and returns NULL.
Examples:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
char buffer[80];
while( gets( buffer ) != NULL ) {
puts( buffer );
}
return EXIT_SUCCESS;
}
Classification:
ANSI, POSIX 1003.1 OB. This function is marked as obsolescent, and may be removed from a future version of the POSIX standard. It's already been removed from C11.
Safety: | |
---|---|
Cancellation point | Yes |
Signal handler | No |
Thread | Yes |
Page updated: