fputs function and FPUTC function __ function

Source: Internet
Author: User
fputs function
Function: Writes a string to the specified file (not automatically writes the string end Tag ' "). When a string is successfully written, the position pointer of the file is automatically moved back, and the function returns a non-negative integer; otherwise, EOF (symbolic constant with a value of-1) is returned.
function format: int fputs (STR,FP)
Argument: STR is a character pointer, can be a string constant, or the first address of an array that holds a string.
Obtained by opening the file function fopen ().
The function of the fputs function is to write a string to the specified file, which is called: fputs (string, file pointer) where the string can be a string constant, or it can be a character array name, or a pointer variable
#include
#include
int main ()
{
    char str[80]= "asdhfdf\n";
    FILE *FP = NULL;
    if ((Fp=fopen ("Strfile.txt", "W")) ==null)
    {
       printf ("Cannot open file\n");
       Exit (0);
    }
    Fputs (STR,FP); Putchar (str);
    Fclose (FP);
    fp = NULL;
    return 0;
}

FPUTC function
function function: Writes the character Ch to the position of the current write pointer of the file pointed to by the file pointer FP.
function format: int FPUTC (int c, FILE *FP).
Parameter explanation: FP is a file pointer, and its value is obtained when executing fopen () Open file.
n is the number of characters for the output.
Although the function is defined as an integer number, it is only eight bits low.

return value: In normal invocation, the function returns the ASCII value of the character written to the file, and when an error returns EOF (-1). When a character or byte of data is correctly written, the internal write pointer in the file automatically moves back to the position of one byte. EOF is a macro defined in the header file stdio.h.

#include 
#include 
void Main ()
{
    file* fpout;
    char ch;
    if ((Fpout=fopen ("File_a.dat", "W")) ==null)
    {
        printf ("error!\n");
        Exit;
    }
    Ch=getchar ();
    for (; ch!= ' # ';)
    {
        FPUTC (ch,fpout);
        Ch=getchar ();   Cannot write only GetChar ();
    }
    Fclose (fpout);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.