Main Page | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

Printf - Print formatted data to stdout


Files

file  otPrintf.h
 Printf Library.

Modules

 Version History
 printf - Code example

Functions

unsigned printf (const char *fmt,...)
 Print formatted data to stdout. Writes the C string pointed by format to the standard output (stdout). If format includes format specifiers (subsequences beginning with ), the additional arguments following format are formatted and inserted in the resulting string replacing their respective specifiers.
unsigned sprintf (char *buf, const char *fmt,...)
 Write formatted data to string. Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str. The size of the buffer should be large enough to contain the entire resulting string (see snprintf for a safer version). A terminating null character is automatically appended after the content. After the format parameter, the function expects at least as many additional arguments as needed for format.
unsigned vsprintf (char *buf, const char *fmt, va_list args)
 Write formatted data from variable argument list to string. Composes a string with the same text that would be printed if format was used on printf, but using the elements in the variable argument list identified by arg instead of additional function arguments and storing the resulting content as a C string in the buffer pointed by s. Internally, the function retrieves arguments from the list identified by arg as if va_arg was used on it, and thus the state of arg is likely to be altered by the call. In any case, arg should have been initialized by va_start at some point before the call, and it is expected to be released by va_end at some point after the call.
unsigned xformat (void(*outchar)(void *arg, char), void *arg, const char *fmt,...)
unsigned xvformat (void(*outchar)(void *arg, char), void *arg, const char *fmt, va_list args)
 Printf like format function.
void setStdout (unsigned len, U8 chan)
 Init procedure. Call this function as first at program setup time. It allocate a buffer for printf functions and set the standard output.
void stdOutLF ()
 Send on standard out a line feed character.
char * printfBuffer ()
 Return pointer to printf buffer.

Detailed Description

Dependency: SERIAL - Procedure for serial usage, Malloc - Memory management

Function Documentation

unsigned printf const char *  fmt,
  ...
 

Parameters:
fmt C string that contains the text to be written to stdout. It can optionally contain embedded format specifiers that are replaced by the values specified in subsequent additional arguments and formatted as requested.
... Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n). There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.
Returns:
On success, the total number of characters written is returned.

char* printfBuffer  ) 
 

void setStdout unsigned  len,
U8  chan
 

Parameters:
len Size in byte of the buffer
chan Specify the used uart for stdout. Use UartId

unsigned sprintf char *  buf,
const char *  fmt,
  ...
 

Parameters:
buf Pointer to a buffer where the resulting C-string is stored. The buffer should be large enough to contain the resulting string.
fmt C string that contains a format string that follows the same specifications as format in printf (see printf for details).
... Depending on the format string, the function may expect a sequence of additional arguments, each containing a value to be used to replace a format specifier in the format string (or a pointer to a storage location, for n). There should be at least as many of these arguments as the number of values specified in the format specifiers. Additional arguments are ignored by the function.
Returns:
On success, the total number of characters written is returned. This count does not include the additional null-character automatically appended at the end of the string. On failure, a negative number is returned.

void stdOutLF  ) 
 

unsigned vsprintf char *  buf,
const char *  fmt,
va_list  args
 

Parameters:
buf Pointer to a buffer where the resulting C-string is stored. The buffer should be large enough to contain the resulting string.
fmt C string that contains a format string that follows the same specifications as format in printf (see printf for details).
args A value identifying a variable arguments list initialized with va_start. va_list is a special type defined in <stdarg.h>.
Returns:
On success, the total number of characters written is returned. On failure, a negative number is returned.

unsigned xformat void(*)(void *arg, char)  outchar,
void *  arg,
const char *  fmt,
  ...
 

Printf like format function.

General format :

[width][.precision][flags]type

  • width Is the minimum size of the field.

  • precision Is the maximum size of the field.

Supported flags :

  • l With integer number the argument will be of type long.
  • ll With integer number the argument will be of type long long.
  • Space for positive integer a space will be added before.
  • z Compatible with C99 the argument is size_t (aka sizeof(void *))
  • + A + sign prefix positive number.
  • # A prefix will be printed (o for octal,0x for hex,0b for binary)
  • 0 Value will be padded with zero (default is spacwe)
  • - Left justify as default filed have rigth justification.

Supported type :

  • s Null terminated string of char.
  • S Null terminated string of char in upper case.
  • i Integer number.
  • d Integer number.
  • u Unsigned number.
  • x Unsigned number in hex.
  • X Unsigned number in hex upper case.
  • b Binary number
  • o Octal number
  • p Pointer will be emitted with the prefix ->
  • P Pointer in upper case letter.
  • f Floating point number.
  • B Boolean value printed as True / False.

Parameters:
outchar - Pointer to the function to output one char.
arg - Argument for the output function.
fmt - Format options for the list of parameters.
Returns:
The number of char emitted.

unsigned xvformat void(*)(void *arg, char)  outchar,
void *  arg,
const char *  fmt,
va_list  args
 

Parameters:
outchar Pointer to the function to output one new char.
arg Argument for the output function.
fmt Format options for the list of parameters.
args Arguments
footer

otStudio - Library Reference - (C) 2020-23 Officina Turini, All Rights Reserved
Document built with Doxygen 1.4.0