annotate docs/ccguide/getc.refentry @ 1504:d3a421a9f13f

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