About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/fputs.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 fputs Context: slangrtl

Synopsis

Write a string to an open stream

Syntax

Integer_Type fputs (String_Type s, File_Type fp);

Description

The fputs function writes the string s to the open file pointer fp. It returns -1 upon failure and sets errno, otherwise it returns the length of the string.

Example

The following function opens a file in append mode and uses the fputs function to write to it.

    define append_string_to_file (str, file)
    {
       variable fp;
       fp = fopen (file, "a");
       if (fp == NULL) verror ("Unable to open %s", file);
       if ((-1 == fputs (s, fp))
           or (-1 == fclose (fp)))
         verror ("Error writing to %s", file);
    }

One must not disregard the return value from the fputs function, as many C programmers do. Doing so may lead to a stack overflow error.

To write an object that contains embedded null characters, use the fwrite function.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.