gets_s

From RAD Studio
Jump to: navigation, search

Go Up to stdio.h Index


Header File

stdio.h

Category

Character input/output functions

Prototype

char *gets_s(char *s, rsize_t n);

Description

Replaces gets, getws adding security enhancements.

gets_s collects n number of characters from stdin and puts them into s. The maximum number of characters gets_s can read is n-1.

In case of a run-time constraint violation, s[0] is set to null, and an undetermined number of characters are read from stdin and discarded, until a new line character, EOF, or a read error is encountered.

Note: For Win32 GUI applications, stdin must be redirected.

Note: fgets, fgetws allows for proper handling of reading input lines that cannot be stored in the result array. End users should consider using fgets, fgetws instead of gets_s.

Return Value

On success, get_s returns the string argument s.

On end-of-file or error, it returns null.

Example

#include <stdio.h>
int main(void)
{
   char string[80];
   printf("Input a string:");
   gets_s(string,5);
   printf("The string input was: %s\n", string);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

gets_s

+

+

+

+

See Also