fprintf
| Input-Output Functions |
Writes formatted output to a file.
int fprintf( FILE *file_pointer, const char *format_string [, args ] );
| file_pointer | A pointer to a file. |
| format_string | The formatted string to write to the file. |
| args | One or more optional print arguments. |
Return Values
On success, returns the Total number of characters printed. On error, returns a negative number.
For fprintf details, refer to your C language documentation.
Example
The following example opens a log file and writes the id number and group name of the Virtual User to it using fprintf.
#include <stdio.h>
#ifdef unix
char * filename = "/tmp/logfile.txt";
#else
char * filename = "c:\\logfile.txt";
#endif
FILE* file;
int id;
char * groupname;
// Create a new file
if ((file = fopen(filename, "w" )) == NULL) {
lr_output_message("Unable to create %s", filename);
return -1;
}// Write the Vuser ID and group to the log file
lr_whoami(&id, &groupname, NULL); fprintf(file, "log file of virtual user ID: %d group: %s\n", id, groupname); fclose(file);
Example: Written to log file:
log file of virtual user ID: -1 group: None

