Compartilhar via


gets, _getws (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Get a line from the stdin stream.

char *gets(    char*buffer);wchar_t *_getws(    wchar_t*buffer);

Parameters

  • buffer
    Storage location for input string.

Return Values

Each function returns its argument if successful.

A NULL pointer indicates an error or end-of-file condition.

Use ferror or feof to determine which one has occurred.

Remarks

The gets function reads a line from the standard input stream stdin and stores it in buffer. The line consists of all characters up to and including the first newline character ('\n').

gets then replaces the newline character with a null character ('\0') before returning the line. In contrast, the fgets function retains the newline character.

_getws is a wide-character version of gets; its argument and return value are wide-character strings.

Security Remarks

The string to be acquired must not be larger than the maximum number of bytes allowed in buffer; otherwise, a buffer overrun can occur.

This can lead to a denial of service attack against the application if an access violation occurs, or in the worst case, allow an attacker to inject executable code into your process. Consider using an appropriate strsafe function.

For more information, see Safe String Functions.

Generic-Text Routine Mappings

TCHAR.H Routine _UNICODE Defined
_getts _getws

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

/* GETS.C */

#include <stdio.h>

void main( void )
{
   char line[81];

   printf( "Input a string: " );
   gets( line );
   printf( "The line entered was: %s\n", line );
}

Output

Input a string: Hello!
The line entered was: Hello!

Requirements

OS Versions: Windows CE 2.0 and later.
Header: stdlib.h.
Link Library: coredll.dll.

See Also

fgets | fputs | puts

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.