Rev | Author | # | Line |
---|---|---|---|
1 | perry | 1 | !!NAME |
2 | fgetc, fgets, getc, getchar, gets, ungetc - input of characters and strings | ||
3 | !!SYNOPSIS | ||
4 | |||
2 | SamJansen | 5 | __#include <stdio.h>__ |
6 | |||
7 | __int fgetc(FILE *__''stream''__);__ | ||
8 | __char *fgets(char *__''s''__, int__ ''size''__, FILE *__''stream''__);__ | ||
9 | __int getc(FILE *__''stream''__);__ | ||
10 | __int getchar(void);__ | ||
11 | __char *gets(char *__''s''__);__ | ||
12 | __int ungetc(int__ ''c''__, FILE *__''stream''__);__ | ||
1 | perry | 13 | |
14 | !!DESCRIPTION | ||
15 | |||
16 | |||
17 | __fgetc()__ reads the next character from ''stream'' | ||
18 | and returns it as an __unsigned char__ cast to an | ||
19 | __int__, or __EOF__ on end of file or | ||
20 | error. | ||
21 | |||
22 | |||
23 | __getc()__ is equivalent to __fgetc()__ except that it | ||
24 | may be implemented as a macro which evaluates ''stream'' | ||
25 | more than once. | ||
26 | |||
27 | |||
28 | __getchar()__ is equivalent to | ||
29 | __getc(__''stdin''__)__. | ||
30 | |||
31 | |||
32 | __gets()__ reads a line from ''stdin'' into the buffer | ||
33 | pointed to by ''s'' until either a terminating newline or | ||
34 | __EOF__, which it replaces with __'0'__. No check for | ||
35 | buffer overrun is performed (see __BUGS__ | ||
36 | below). | ||
37 | |||
38 | |||
39 | __fgets()__ reads in at most one less than ''size'' | ||
40 | characters from ''stream'' and stores them into the | ||
41 | buffer pointed to by ''s''. Reading stops after an | ||
42 | __EOF__ or a newline. If a newline is read, it is stored | ||
43 | into the buffer. A __'0'__ is stored after the last | ||
44 | character in the buffer. | ||
45 | |||
46 | |||
47 | __ungetc()__ pushes ''c'' back to ''stream'', cast | ||
48 | to __unsigned char__, where it is available for | ||
49 | subsequent read operations. Pushed - back characters will be | ||
50 | returned in reverse order; only one pushback is | ||
51 | guaranteed. | ||
52 | |||
53 | |||
54 | Calls to the functions described here can be mixed with each | ||
55 | other and with calls to other input functions from the | ||
56 | __stdio__ library for the same input stream. | ||
57 | !!RETURN VALUE | ||
58 | |||
59 | |||
60 | __fgetc()__, __getc()__ and __getchar()__ return | ||
61 | the character read as an __unsigned char__ cast to an | ||
62 | __int__ or __EOF__ on end of file or | ||
63 | error. | ||
64 | |||
65 | |||
66 | __gets()__ and __fgets()__ return ''s'' on success, | ||
67 | and __NULL__ on error or when end of file occurs while no | ||
68 | characters have been read. | ||
69 | |||
70 | |||
71 | __ungetc()__ returns ''c'' on success, or __EOF__ | ||
72 | on error. | ||
73 | !!CONFORMING TO | ||
74 | |||
75 | |||
3 | JohnMcPherson | 76 | [ANSI] - C, [POSIX].1 |
1 | perry | 77 | !!BUGS |
78 | |||
79 | |||
80 | Never use __gets()__. Because it is impossible to tell | ||
81 | without knowing the data in advance how many characters | ||
82 | __gets()__ will read, and because __gets()__ will | ||
83 | continue to store characters past the end of the buffer, it | ||
84 | is extremely dangerous to use. It has been used to break | ||
85 | computer security. Use __fgets()__ instead. | ||
86 | |||
87 | |||
88 | It is not advisable to mix calls to input functions from the | ||
89 | __stdio__ library with low - level calls to __read()__ | ||
90 | for the file descriptor associated with the input stream; | ||
91 | the results will be undefined and very probably not what you | ||
92 | want. | ||
93 | !!SEE ALSO | ||
94 | |||
95 | |||
96 | read(2), write(2), fopen(3), | ||
97 | fread(3), scanf(3), puts(3), | ||
98 | fseek(3), ferror(3) | ||
99 | ---- |
lib/blame.php:177: Warning: Invalid argument supplied for foreach() (...repeated 3 times)