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);
}