FWriteFmtLn

Table of Contents

FWriteFmtLn

Description

Write formatted output to a file stream followed by a newline character. This macro internally uses StrWriteFmtInternal to format the string and then writes it to the stream followed by a newline.

Parameters

NameDirectionDescription
streaminPointer to the FILE stream to write to.
fmtstrinFormat string with {} placeholders. should be wrapped with variable.

Success

Placeholders in fmtstr are replaced by the passed arguments, and the resulting formatted string followed by a newline is written to the stream.

Failure

Failure might occur during memory allocation for the temporary string or during the write operation to the stream (fputs or fputc). Errors from StrWriteFmtInternal (logging messages) might also occur.

Usage example (Cross-references)

    Str file_name = StrInit();
    StrWriteFmt(&file_name, "{}/misra-{}-{}", log_dir, SysGetCurrentProcessId(), &time_buffer[0]);
    FWriteFmtLn(stderr, "storing logs in {}", file_name.data);
    
    // Open the file for writing (create if it doesn't exist, overwrite if it does)
    Str syserr;
    StrInitStack(syserr, SYS_ERROR_STR_MAX_LENGTH, {
    FWriteFmtLn(stderr, "Error opening log file, will write logs to stderr");
    });
    stderror = stderr;
    int main(int argc, char **argv) {
    if (argc != 2) {
    FWriteFmtLn(stderr, "USAGE : {} config.json", argc == 0 ? "MisraDoc" : argv[0]);
    return 1;
    }
    
    if (argc < 2 || argc > 3) {
    FWriteFmtLn(stderr, "USAGE : {} <enum-json-spec> [output-file-name]", argc == 0 ? "MisraEnum" : argv[0]);
    return 1;
    }
    /// TAGS: Macro, Convenience, Stdout, I/O
    ///
    #define WriteFmtLn(...) FWriteFmtLn(stdout, __VA_ARGS__)
    
    ///

Share :

Related Posts

FWriteFmt

FWriteFmt Description Write formatted output to a file stream. This macro internally uses StrWriteFmtInternal to format the string and then writes it to the stream.

Read More

void

void Description Type-specific write callback signature

Read More

ReadCompleteFile

ReadCompleteFile Description Read complete contents of file at once. Pointer returned is malloc’d and hence must be freed after use. The returned pointer can also be reused by providing pointer to it in data parameter. realloc is called on *data in order to expand it’s size. If *capacity exceeds the size of file to be loaded, then no reallocation is performed. This means the provided buffer will automatically be expanded if required. The returned buffer is null-terminated just-in-case. The implementation and API is designed in such a way that it can be used with containers like Vec and Str.

Read More