Share this page

# fputc

Input-Output Functions

Writes a character to a stream.

    int fputc( int c, FILE *file_pointer);

c | The character to place in the stream.
file_pointer | A pointer to a file.

## Return Values

If there are no errors, returns the written character. If an error occurs, returns EOF.

## Example

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

Copy code

        #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 26.1-26.3 Function Reference 26.1-26.3 All View Local Help Center View Online Help Center Version: