Example: fprintf

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);
Written to log file:
log file of virtual user ID: -1 group: None