File:  [MW Coherent from dump] / coherent / a / usr / man / ALL / gets
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Wed May 29 04:56:34 2019 UTC (7 years ago) by root
Branches: MarkWilliams, MAIN
CVS tags: relic, HEAD
coherent



gets()                    STDIO Function                   gets()




Read string from standard input

#include <stdio.h>
cchhaarr *ggeettss(_b_u_f_f_e_r) cchhaarr *_b_u_f_f_e_r;

gets  reads characters  from  the standard  input  into a  buffer
pointed at by  _b_u_f_f_e_r.  It stops reading as soon  as it detects a
newline character or EOF.   gets discards the newline or EOF, ap-
pends a null character onto  the string it has built, and returns
another copy of _b_u_f_f_e_r.

***** Example *****

The following example uses ggeettss to get a string from the console;
the string is echoed twice to demonstrate what ggeettss returns.


#include <stdio.h>

main()
{
        char buffer[80];



        printf("Type something: ");



        /*
         * because of the way COHERENT's teletype
         * driver works, the following fflush has
         * no effect.  It should be included for
         * portability to other operating systems.
         */



        fflush(stdout);
        printf("%s\n%s\n", gets(buffer), buffer);
}


***** See Also *****

buffer, fgets(), getc(), STDIO

***** Diagnostics *****

gets returns NULL if an error occurs or if EOF is seen before any
characters are read.





COHERENT Lexicon                                           Page 1




gets()                    STDIO Function                   gets()



***** Notes *****

gets  stops reading  the input  string  as soon  as it  detects a
newline character.   If a previous  input routine left  a newline
character in the standard input buffer, gets will read it and im-
mediately stop accepting  characters; to the user, it will appear
as if gets is not working at all.

For example, if getchar  is followed by gets, the first character
ggeettss  will  receive  is  the  newline  character left  behind  by
ggeettcchhaarr.  A simple statement will remedy this:


        while (getchar() != '\n')
                ;


This throws  away the newline  character left behind  by getchar;
gets will now work correctly.






































COHERENT Lexicon                                           Page 2



unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.