fputs()
Writes a string to a file.
Synopsis
int fputs(string s, file f);
Parameters
Parameter | Description |
---|---|
s | String to be written |
f | File to be written |
Return value
The function returns 0 or a positive number if it was successfully executed. In case of errors the function returns a negative number.
Error
If incorrect data types are used or if file is not open.
Description
Writes the string s to the file f. No "Newline"; is appended.
Example
main()
{
string fname="C:/TEST.TXT",st;
file f;
int i;
i=access(fname,F_OK); // Does the file already exist ?
if (i!=0) // File does not exist yet
{
f=fopen(fname,"w+"); // Create a new file
for (i=0;i<=10;i++) fputs("line "+i+"\n",f); // 10 lines with
endl
rewind(f); // Back to the beginning
while (feof(f)==0) // as long as not at the end of the file
{
fgets(st,20,f); // Import string again
Debug(st); // ...and output it
}
fclose(f); // close file
}
else DebugN("File already exists !");
}
Assignment
CTRL