RAD Studio
ContentsIndex
PreviousUpNext
gets, _getws

Header File 

stdio.h  

Category 

Console I/O Routines 

Prototype 

char *gets(char *s); 

wchar_t *_getws(wchar_t *s); // Unicode version 

Description 

Gets a string from stdin. 

gets collects a string of characters terminated by a new line from the standard input stream stdin and puts it into s. The new line is replaced by a null character (\0) in s. 

gets allows input strings to contain certain whitespace characters (spaces, tabs). gets returns when it encounters a new line; everything up to the new line is copied into s. 

The gets function is not length-terminated. If the input string is sufficiently large, data can be overwritten and corrupted. The fgets function provides better control of input strings.

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

On success, gets 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(string);
   printf("The string input was: %s\n", string);
   return 0;
}

Portability

 
POSIX 
Win32 
ANSI C 
ANSI C++ 
gets 
_getws 
 
 
 
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!