Sophie

Sophie

distrib > Mandriva > 8.1 > i586 > by-pkgid > 700475c8ae73fb4d57b6df4485c29e1c > files > 33

slang-doc-1.4.4-2mdk.i586.rpm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
 <META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
 <TITLE> {The S-lang C Library Reference}: SLang_pop_fileptr</TITLE>
 <LINK HREF="cref-101.html" REL=next>
 <LINK HREF="cref-99.html" REL=previous>
 <LINK HREF="cref.html#toc100" REL=contents>
</HEAD>
<BODY>
<A HREF="cref-101.html">Next</A>
<A HREF="cref-99.html">Previous</A>
<A HREF="cref.html#toc100">Contents</A>
<HR>
<H2><A NAME="SLang_pop_fileptr"></A> <A NAME="s100">100. <B>SLang_pop_fileptr</B></A></H2>

<P>
<DL>
<DT><B> Synopsis </B><DD><P>Pop a file pointer
<DT><B> Usage </B><DD><P><CODE>int SLang_pop_fileptr (SLang_MMT_Type **mmt, FILE **fp)</CODE>
<DT><B> Description </B><DD><P><CODE>SLang_pop_fileptr</CODE> pops a file pointer from the <B>S-lang</B>
run-time stack.  It returns zero upon success, or <CODE>-1</CODE> upon failure.
<P>A <B>S-lang</B> file pointer (SLANG_FILEPTR_TYPE) is actually a memory
managed object.  For this reason, <CODE>SLang_pop_fileptr</CODE> also
returns the memory managed object via the argument list.  It is up
to the calling routine to call <CODE>SLang_free_mmt</CODE> to free the
object.
<DT><B> Example </B><DD><P>The following example illustrates an application defined intrinsic
function that writes a user defined double precision number to a
file.  Note the use of <CODE>SLang_free_mmt</CODE>:
<BLOCKQUOTE><CODE>
<PRE>
     int write_double (void)
     {
        double t;
        SLang_MMT_Type *mmt;
        FILE *fp;
        int status;

        if (-1 == SLang_pop_double (&amp;d, NULL, NULL))
          return -1;
        if (-1 == SLang_pop_fileptr (&amp;mmt, &amp;fp))
          return -1;
        
        status = fwrite (&amp;d, sizeof (double), 1, fp);
        SLang_free_mmt (mmt);
        return status;
     }
</PRE>
</CODE></BLOCKQUOTE>

This function can be used by a <B>S-lang</B> function as follows:
<BLOCKQUOTE><CODE>
<PRE>
     define write_some_values ()
     {
        variable fp, d;

        fp = fopen ("myfile.dat", "wb");
        if (fp == NULL)
          error ("file failed to open");
        for (d = 0; d &lt; 10.0; d += 0.1)
          {
             if (-1 == write_double (fp, d))
               error ("write failed");
          }
        if (-1 == fclose (fp))
          error ("fclose failed");
     }
</PRE>
</CODE></BLOCKQUOTE>
<DT><B> See Also </B><DD><P><CODE>SLang_free_mmt, SLang_pop_double</CODE>
</DL>
<P>
<P>
<P>
<HR>
<A HREF="cref-101.html">Next</A>
<A HREF="cref-99.html">Previous</A>
<A HREF="cref.html#toc100">Contents</A>
</BODY>
</HTML>