Share this page

# Example: fputc

The following example opens a log file and writes the id number and group name of the Virtual User to it using fputc.

        #include <stdio.h>

        #ifdef unix
            char * filename = "/tmp/logfile.txt";
        #else
            char * filename = "c:\\logfile.txt";
        #endif
        FILE* file;
        char * p, str[] = "this is the first line of the log file";
        int c;

        // Create a new file

        if ((file = fopen(filename, "w+" )) == NULL) {
              lr_output_message ("Unable to create %s", filename);
              return -1;
         }

    // Print string to the log file

    // p points to the first character in str

         p = str;

    // Use -1 or EOF
         while ((*p != NULL) && fputc(*(p++), file) != -1);
                 fclose(file);

    Example: Written to log file:
    this is the first line of the log file

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: