Command Prompt for Windows

gets, _wgets, _tgets

char *gets(char *s);
wchar_t *_wgets(wchar_t *s);
TCHAR *_tgets(TCHAR *s);

Get a character string s without the CR-LF character combination.

Parameter Description
s Address of a character array to store the string. This array must be at least 80 characters in size.


On success, it returns the address of the character array, where the NULL terminated character string is stored. On end of file (ie. EOF) or on error, NULL is returned.


Function gets() is streamable, that is, when stdin is redirected on the command line from a file, the character string will be read from the file and will not be echoed to the screen.

Tab characters are converted to a single space character, unless stdin has been redirected on the command line.

See Also

scanf, getch, getchar, putx, puts


#include "woio.h"
#include <dos.h>

/* Determine whether a file exists */

int prompt_open(void)
    char buf[80];
    int handle;

    printf("Enter filename: ");
    if (gets(buf))            /* get a filename */
        if (_dos_open(buf, 0, &handle)
            return handle;        /* opened file */

    return 0;        /* failed to open file */

int main(void)
    int handle;

    if ((handle = prompt_open()) != 0)  {
        printf("File exists\n");
        _dos_close(handle);       /* close the file */
        return 1;

    return 0;