Pegasus InfoCorp: Web site design and web software development company

GETS (3)

input of characters and strings

SYNOPSIS

    #include <stdio.h>
      int fgetc(FILE * stream );  
    
      char *fgets(char * s , int  size , FILE * stream );  
    
      int getc(FILE * stream );  
    
      int getchar(void);  
    
      char *gets(char * s );  
    
      int ungetc(int  c , FILE * stream );  
    

DESCRIPTION

    fgetc() reads the next character from stream and returns it as an unsigned char cast to an int , or EOF on end of file or error.

    getc() is equivalent to fgetc() except that it may be implemented as a macro which evaluates stream more than once.

    getchar() is equivalent to getc( stdin ) \fR.

    gets() reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF , which it replaces with '\e0' . No check for buffer overrun is performed (see BUGS below).

    fgets() reads in at most one less than size characters from stream and stores them into the buffer pointed to by s . Reading stops after an EOF or a newline. If a newline is read, it is stored into the buffer. A '\e0' is stored after the last character in the buffer.

    ungetc() pushes c back to stream , cast to unsigned char where it is available for subsequent read operations. Pushed - back characters will be returned in reverse order; only one pushback is guaranteed.

    Calls to the functions described here can be mixed with each other and with calls to other input functions from the stdio library for the same input stream.

RETURN VALUES

    fgetc() , getc() and getchar() return the character read as an unsigned char cast to an int or EOF on end of file or error.

    gets() and fgets() return s on success, and NULL on error or when end of file occurs while no characters have been read.

    ungetc() returns c on success, or EOF on error.

CONFORMING TO

    ANSI - C, POSIX.1

BUGS

    Because it is impossible to tell without knowing the data in advance how many characters gets() will read, and because gets() will continue to store characters past the end of the buffer, it is extremely dangerous to use. It has been used to break computer security. Use fgets() instead.

    It is not advisable to mix calls to input functions from the stdio library with low - level calls to read() for the file descriptor associated with the input stream; the results will be undefined and very probably not what you want.

SEE ALSO

    - read (2) - - write (2) - - fopen (3) - - fread (3) - - scanf (3) - - puts (3) - - fseek (3) - - ferror (3) - ' " ' " Copyright(c) 1994 The Regents of the University of California ' " Copyright(c) 1994-1996 Sun Microsystems Inc ' " ' " See the file "license terms" for information on usage and redistribution ' " of this file and for a DISCLAIMER OF ALL WARRANTIES ' " ' " RCS: @(#) $Id: GetScroll 3 v 1 2 1998/09/14 18:22:51 stanton Exp $ ' " ' " The definitions below are for supplemental macros used in Tcl/Tk ' " manual entries ' " ' " AP type name in/out ?indent? ' " Start paragraph describing an argument to a library procedure ' " type is type of argument(int etc ) in/out is either "in" "out" ' " or "in/out" to describe whether procedure reads or modifies arg ' " and indent is equivalent to second arg of IP(shouldn't ever be ' " needed; use AS below instead) ' " ' " AS ?type? ?name? ' " Give maximum sizes of arguments for setting tab stops Type and ' " name are examples of largest possible arguments that will be passed ' " to AP later If args are omitted default tab stops are used ' " ' " BS ' " Start box enclosure From here until next BE everything will be ' " enclosed in one large box ' " ' " BE ' " End of box enclosure ' " ' " CS ' " Begin code excerpt ' " ' " CE ' " End code excerpt ' " ' " VS ?version? ?br? ' " Begin vertical sidebar for use in marking newly-changed parts ' " of man pages The first argument is ignored and used for recording ' " the version when the VS was added so that the sidebars can be ' " found and removed when they reach a certain age If another argument ' " is present then a line break is forced before starting the sidebar ' " ' " VE ' " End of vertical sidebar ' " ' " DS ' " Begin an indented unfilled display ' " ' " DE ' " End of indented unfilled display ' " ' " SO ' " Start of list of standard options for a Tk widget The ' " options follow on successive lines in four columns separated ' " by tabs ' " ' " SE ' " End of list of standard options for a Tk widget ' " ' " OP cmdName dbName dbClass ' " Start of description of a specific option cmdName gives the ' " option's name as specified in the class command dbName gives ' " the option's name in the option database and dbClass gives ' " the option's class in the option database ' " ' " UL arg1 arg2 ' " Print arg1 underlined then print arg2 normally ' " ' " RCS: @(#) $Id: man macros v 1 2 1998/09/14 18:39:54 stanton Exp $ ' " ' " # Set up traps and other miscellaneous stuff for Tcl/Tk man pages t wh -1 3i ^B ^l n( l b ' " # Start an argument description AP !" $4"" TP $4 { !" $2"" TP n()Cu 15