466
|
1 <refentry id="getc">
|
|
2 <refnamediv>
|
570
|
3 <refname>Getc</refname>
|
|
4 <refname>Getchar</refname>
|
|
5 <refname>Getw</refname>
|
|
6 <refpurpose>return next character to be read from a file</refpurpose>
|
466
|
7 </refnamediv>
|
|
8
|
|
9 <refsynopsisdiv>
|
|
10 <funcsynopsis>
|
468
|
11 <funcsynopsisinfo>
|
|
12 #include <stdio.h>
|
|
13 </funcsynopsisinfo>
|
570
|
14
|
466
|
15 <funcprototype>
|
570
|
16 <funcdef>int <function>getc</function></funcdef>
|
|
17 <paramdef>FILE *<parameter>fp</parameter></paramdef>
|
|
18 </funcprototype>
|
|
19 <funcprototype>
|
|
20 <funcdef>int <function>getchar</function></funcdef>
|
636
|
21 <void/>
|
570
|
22 </funcprototype>
|
|
23 <funcprototype>
|
|
24 <funcdef>int <function>getw</function></funcdef>
|
|
25 <paramdef>FILE *<parameter>fp</parameter></paramdef>
|
466
|
26 </funcprototype>
|
|
27 </funcsynopsis>
|
|
28
|
|
29 </refsynopsisdiv>
|
|
30
|
|
31 <refsect1><title>Description</title>
|
|
32 <para>
|
597
|
33 Getc returns the next character from the file pointed to by
|
|
34 "fp".
|
|
35 </para>
|
|
36 <para>
|
|
37 Getchar is equivalent to "getc(stdin)".
|
|
38 </para>
|
|
39 <para>
|
|
40 Getw returns the next two bytes from the file as an integer.
|
|
41 </para>
|
|
42 <para>
|
|
43 Under OS-9 there is a choice of service requests to use when
|
|
44 reading from a file. "Read()" will get characters up to a
|
|
45 specified number in "raw" mode i.e. no editing will take
|
|
46 place on the input stream and the characters will appear to the
|
|
47 program exactly as in the file. "Readln()", on the other
|
|
48 hand, will honor the various mappings of characters
|
|
49 associated with a Serial Character device such as a terminal
|
|
50 and in any case will return to the caller as soon as a carriage
|
|
51 return is seen on the input.
|
|
52 </para>
|
|
53 <para>
|
|
54 In the vast majority of cases, it is preferable to use
|
|
55 "readln()" for accessing Serial Character devices and "read()"
|
|
56 for any other file input. "Getc()" uses this strategy and, as
|
|
57 all file input using the Standard Library functions is routed
|
|
58 through "getc()", so do all the other input functions. The
|
|
59 choice is made when the first call to "getc()" is made after
|
|
60 the file has been opened. The system is consulted for the
|
|
61 status of the file and a flag bit is set in the file structure
|
|
62 accordingly. The choice may be forced by the programmer by
|
|
63 setting the relevant bit before a call to "getc()". The flag
|
|
64 bits are defined in "<stdio.h>" and "_SCF" and "_RBF" and the
|
|
65 method is as follows: assuming that the file pointer for the
|
|
66 file, as returned by "fopen()" is f,
|
|
67 <programlisting>
|
|
68 f->_flag |= _SCF;
|
|
69 </programlisting>
|
|
70 will force the use of "readln()" on input and
|
|
71 <programlisting>
|
|
72 f->_flag |= _RBF;
|
|
73 </programlisting>
|
|
74 will force the use of "read()". This trick may be played on
|
|
75 the standard streams "stdin", "stdout" and "stderr" without the
|
|
76 need for calling "fopen()" but before any input is requested
|
|
77 from the stream.
|
466
|
78 </para>
|
|
79 </refsect1>
|
542
|
80
|
552
|
81 <refsect1><title>Diagnostics</title>
|
|
82 <para>
|
|
83 EOF(-1) is returned for end of file or error.
|
|
84 </para>
|
|
85 </refsect1>
|
|
86
|
542
|
87 <refsect1><title>See Also</title>
|
|
88 <para>
|
|
89 <link linkend="putc">Putc()</link>,
|
|
90 <link linkend="fread">fread()</link>,
|
|
91 <link linkend="fopen">fopen()</link>,
|
|
92 <link linkend="gets">gets()</link>,
|
|
93 <link linkend="ungetc">ungetc()</link>
|
|
94 </para>
|
|
95 </refsect1>
|
|
96
|
466
|
97 </refentry>
|