Design Pattern Examples
Overview of object-oriented design patterns
formatstring.c File Reference

Implementation of the formatstring() function that replaces sprintf() and snprintf() by allocating the right-sized buffer and returning it. More...

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include "formatstring.h"
Include dependency graph for formatstring.c:

Go to the source code of this file.

Functions

char * formatstring (const char *format,...)
 Use the given string and arguments to return a buffer containing the formatted string. The format and arguments follow the printf() functionality.
 

Detailed Description

Implementation of the formatstring() function that replaces sprintf() and snprintf() by allocating the right-sized buffer and returning it.

Definition in file formatstring.c.

Function Documentation

◆ formatstring()

char * formatstring ( const char *  format,
  ... 
)

Use the given string and arguments to return a buffer containing the formatted string. The format and arguments follow the printf() functionality.

Parameters
formatString containing formatting codes as used with the printf() function.
Returns
Returns a newly allocated buffer containing the zero-terminated formatted string. Use free() to delete the buffer. Returns NULL if no memory could be allocated.

Definition at line 15 of file formatstring.c.

Referenced by _Bridge_Exercise_Demonstrate_Logging(), _Decorate(), _Real_DoWork(), Composite_Exercise_FormatEntry(), Memento_ApplyReplaceOperation(), Message_ToString(), MessagePosition_ToString(), MessageWindow_ToString(), and WindowRectangle_ToString().