Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

clearerr(3)

feof(3)

ferror(3)

fgetws(3)

fileno(3)

fopen(3)

fputws(3)

fread(3)

getc(3)

getwc(3)

puts(3)

scanf(3)

gets(3)  —  Subroutines

NAME

gets, fgets − Get a string from a stream

LIBRARY

Standard I/O Library (libc.a)

SYNOPSIS

#include <stdio.h>

char ∗gets(
        char ∗string);

char ∗fgets(
        char ∗string,
        int n,
        FILE ∗stream);

PARAMETERS

stringPoints to a string to receive bytes. 

nSpecifies an upper bound on the number of bytes to read. 

streamPoints to the FILE structure of an open file. 

DESCRIPTION

The gets() function reads bytes from the standard input stream, stdin, into the array pointed to by the string parameter. Data is read until a newline character is read or an End-of-File condition is encountered. If reading is stopped due to a newline character, the newline character is discarded and the string is terminated with a NULL character. 

The fgets() function reads bytes from the data pointed to by the stream parameter into the array pointed to by the string parameter. Data is read until n-1 bytes have been read, until a newline character is read and transferred to string, or until an EOF (End-of-File) condition is encountered. The string is then terminated with a NULL character. 

NOTES

AES Support Level:
Full use.

CAUTIONS

The gets() function does not check the input for a maximum size. Consequently, if more bytes are entered than will fit in the space allocated for the string parameter, gets() will write beyond the end of the allocated space, producing indeterminate results. To avoid this condition, use fgets() instead of gets(). 

RETURN VALUES

If the end of the file is encountered and no characters have been read, no characters are transferred to string and a NULL pointer is returned. If a read error occurs, a NULL pointer is returned. Otherwise, string is returned. 

RELATED INFORMATION

Functions: clearerr(3), feof(3), ferror(3), fgetws(3), fileno(3), fopen(3), fputws(3), fread(3), getc(3), getwc(3), puts(3), scanf(3). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026