Share this page

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

    Example: Written to log file:
    log file of virtual user ID: -1 group: None

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: