📄 libsdeb5.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="GENERATOR" content="Quadralay WebWorks Publisher Professional Edition 6.0.5">
<meta name="TEMPLATEBASE" content="book_html">
<meta name="LASTUPDATED" content="12/04/03 16:07:07">
<title>16.4 File access</title>
<STYLE TYPE="text/css">
<!--
span.Signal { text-transform: uppercase; font-family: Verdana }
-->
</STYLE>
</head>
<body link="#3366CC" vlink="#9999CC" text="#000000" alink="#0000CC" bgcolor="#FFFFFF"
background="images/backgrnd.gif">
<p><img src="images/stlogo.gif" width="106" height="83" align="left"
alt="logo here!"> </p>
<table width="331" border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td><a href="a_refman.htm"><img src="images/navtoc.gif" width="84" height="23"
border="0" alt="TOC"> </a></td>
<td><a href="libsdeb4.htm"><img src="images/navprev.gif" width="80" height="23"
border="0" alt="PREV"> </a></td>
<td><a href="libsdeb6.htm"><img src="images/navnext.gif" width="83" height="23"
border="0" alt="NEXT"> </a></td>
<td><a href="a_refmaa.htm"><img src="images/navidx.gif" width="84" height="23"
border="0" alt="INDEX"> </a></td>
</tr>
</table>
<p><br clear="all">
</p>
<hr align="left">
<blockquote>
<h2>
<a name="1204573"> </a><font color="#003366" face="Verdana, Arial, Helvetica, sans-serif">16.4 File access</font>
</h2><hr>
<p>
<a name="1204575"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">The application can read and write host files. A file is opened using <font size=2 face=Courier><strong>debugopen</strong></font>, which takes the standard ANSI file mode string, as used by <font size=2 face=Courier><strong>fopen</strong></font>, to define the type of file. The function returns the integer file descriptor, which must be used for subsequent reads, writes and to close the file. If an error occurs then <font size=2 face=Courier><strong>-1</strong></font> is returned. The following code opens an output file named <font size=2 face=Courier><strong>testout.dat</strong></font> in binary mode:</font>
</p>
<a name="1204576"> </a><font size=2 face=Courier><strong>#define ERROR -1<br><br></strong></font>
<a name="1204578"> </a><font size=2 face=Courier><strong>long int outfile;<br><br></strong></font>
<a name="1204580"> </a><font size=2 face=Courier><strong>outfile = debugopen("testout.dat", "wb");<br>if (outfile == ERROR) debugmessage ("Can't open testout.dat");<br></strong></font>
<p>
<a name="1204582"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">Similarly, the following code opens an input file named <font size=2 face=Courier><strong>testin.dat</strong></font>:</font>
</p>
<a name="1204583"> </a><font size=2 face=Courier><strong>#define ERROR -1<br><br></strong></font>
<a name="1204585"> </a><font size=2 face=Courier><strong>long int infile;<br><br></strong></font>
<a name="1204587"> </a><font size=2 face=Courier><strong>infile = debugopen("testin.dat", "r");<br>if (infile == ERROR) debugmessage ("Can't open testin.dat");<br></strong></font>
<p>
<a name="1204589"> </a><font size=2 face="Verdana, Arial, Helvetica, sans-serif">An output file can be written to using <font size=2 face=Courier><strong>debugwrite</strong></font>. This takes the number of bytes to be written as a parameter and returns the actual number of bytes written, or <font size=2 face=Courier><strong>0</strong></font> if there is an error.</font>
</p>
<a name="1204590"> </a><font size=2 face=Courier><strong>char *test_string = "Hello World";<br>long int num_bytes_written;<br>num_bytes_written =<br>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -