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
|
<html lang="en">
<head>
<title>Simple Output - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions">
<link rel="prev" href="Opening-and-Closing-Files.html#Opening-and-Closing-Files" title="Opening and Closing Files">
<link rel="next" href="Line_002dOriented-Input.html#Line_002dOriented-Input" title="Line-Oriented Input">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Simple-Output"></a>
Next: <a rel="next" accesskey="n" href="Line_002dOriented-Input.html#Line_002dOriented-Input">Line-Oriented Input</a>,
Previous: <a rel="previous" accesskey="p" href="Opening-and-Closing-Files.html#Opening-and-Closing-Files">Opening and Closing Files</a>,
Up: <a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a>
<hr>
</div>
<h4 class="subsection">14.2.2 Simple Output</h4>
<p>Once a file has been opened for writing a string can be written to the
file using the <code>fputs</code> function. The following example shows
how to write the string ‘<samp><span class="samp">Free Software is needed for Free Science</span></samp>’
to the file ‘<samp><span class="samp">free.txt</span></samp>’.
<pre class="example"> filename = "free.txt";
fid = fopen (filename, "w");
fputs (fid, "Free Software is needed for Free Science");
fclose (fid);
</pre>
<!-- file-io.cc -->
<p><a name="doc_002dfputs"></a>
<div class="defun">
— Built-in Function: <b>fputs</b> (<var>fid, string</var>)<var><a name="index-fputs-777"></a></var><br>
<blockquote><p>Write a string to a file with no formatting.
<p>Return a non-negative number on success and EOF on error.
<!-- Texinfo @sp should work but in practice produces ugly results for HTML. -->
<!-- A simple blank line produces the correct behavior. -->
<!-- @sp 1 -->
<p class="noindent"><strong>See also:</strong> <a href="doc_002dscanf.html#doc_002dscanf">scanf</a>, <a href="doc_002dsscanf.html#doc_002dsscanf">sscanf</a>, <a href="doc_002dfread.html#doc_002dfread">fread</a>, <a href="doc_002dfprintf.html#doc_002dfprintf">fprintf</a>, <a href="doc_002dfgets.html#doc_002dfgets">fgets</a>, <a href="doc_002dfscanf.html#doc_002dfscanf">fscanf</a>.
</p></blockquote></div>
<p>A function much similar to <code>fputs</code> is available for writing data
to the screen. The <code>puts</code> function works just like <code>fputs</code>
except it doesn't take a file pointer as its input.
<!-- file-io.cc -->
<p><a name="doc_002dputs"></a>
<div class="defun">
— Built-in Function: <b>puts</b> (<var>string</var>)<var><a name="index-puts-778"></a></var><br>
<blockquote><p>Write a string to the standard output with no formatting.
<p>Return a non-negative number on success and EOF on error.
</p></blockquote></div>
</body></html>
|