blob: 356986c51bce9ccaf1d4877bc853e5ed8d929f1a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
<title>Input and Output</title>
<body bgcolor="#ffffcc">
<hr>
<center>
<h1>Input and Output</h1>
</center>
<hr>
<p>
The C language does not have any I/O capability! You can access
files and devices via two groups of functions, these can be split
as shown below.<p>
<ul>
<li><a href=#low>Low level.</a>
<li><a href=#ansi>ANSI.</a>
</ul>
<a name=low>
<h2>Low Level I/O</h2>
Low level functions provide direct access to files and devices. If you
only need file read and write you should use the
<a href=#ansi>ANSI</a> functions as your code will remain portable.
If you want to access things like, serial ports, virtual memory and
tape drives, low level I/O is for you.<p>
Low level functions reference files by a
<a href=../glossary.html#filedes>file descriptor</a>, this descriptor
is created with the <a href=../FUNCTIONS/open.html>open</a> function and
can be referenced by functions like:<p>
<a href=../FUNCTIONS/close.html>close</a><br>
<a href=../FUNCTIONS/read.html>read</a><br>
<a href=../FUNCTIONS/write.html>write</a><br>
mmap - Memory map (Not supported on Linux).<br>
<a href=../MAN/ioctl.htm>ioctl</a> I/O control.<p>
Three 'file descripters' are opened automatically when your program runs.
These are:
<pre>
File Default
Desc Name device
---- ---- ------
0 <a href=stdfiles.html>stdin</a> Keyboard
1 <a href=stdfiles.html>stdout</a> Screen
2 <a href=stdfiles.html>stderr</a> Screen
</pre>
If you want to use these 'file descriptors', you do not have to issue an
'open'.
<a name=ansi>
<h2>ANSI standard functions</h2>
These functions are defined in the
<a href=../FUNCTIONS/funcref.htm#stdio>stdio.h</a> header.
The important thing to remember with these functions is the data
is presented in a consistant manor across all platforms. A record
is considered to be 0 or more characters followed by a
<a href=../FUNCTIONS/escape.html>newline</a> character.
If the actual (physical) record is terminated in some other way, the
functions will perform the conversion for you.
<hr>
<p>
<center>
<table border=2 width=80% bgcolor=ivory>
<tr align=center>
<td width=25%>
<a href="../cref.html" target="_top">Top</a>
</td><td width=25%>
<a href="../master_index.html" target="_top">Master Index</a>
</td><td width=25%>
<a href="../SYNTAX/keywords.html" target="_top">C Keywords</a>
</td><td width=25%>
<a href="../FUNCTIONS/funcref.htm" target="_top">Functions</a>
</td>
</tr>
</table>
</center>
<p>
<hr>
<address>Martin Leslie
<script language="JavaScript">
<!-- //
document.write(document.lastModified);
// -->
</script>
</address>
|