Sprint Library
The mikroC PRO for ARM provides the standard ANSI C Sprintf function for easy data formatting.

sprintf
function (sprinti
and sprintl
)
These functions take less ROM and RAM and may be more convenient for use in some cases.
Library Dependency Tree

Functions
sprintf
Prototype |
signed int sprintf(char *wh, const code char *f,...); |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Returns |
The function returns the number of characters actually written to destination string. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Description |
Parameters :
The The format string is read from left to right. The first format specification encountered refers to the first argument after % [flags] [width] [.precision] [{ l | L }] conversion_type Each field in the format specification can be a single character or a number which specifies a particular format option. The
The
The The
The optional characters You must ensure that the argument type matches that of the format specification. You can use type casts to ensure that the proper type is passed to |
sprintl
Prototype |
signed int sprintl(char *wh, const code char *f,...); |
---|---|
Returns |
The function returns the number of characters actually written to destination string. |
Description |
The same as sprintf, except it doesn't support float-type numbers. |
sprinti
Prototype |
signed int sprinti(char *wh, const code char *f,...); |
---|---|
Returns |
The function returns the number of characters actually written to destination string. |
Description |
The same as sprintf, except it doesn't support long integers and float-type numbers. |
Library Example
This is a demonstration of the standard C library sprintf routine usage. Three different representations of the same floating poing number obtained by using the sprintf routine are sent via UART.
float ww = -1.2587538e+1; char buffer[15]; char uart_rd; void main(){ UART0_Init(115200); Delay_ms(100); // Wait for UART module to stabilize UART0_Write_Text("Floating point number representation"); // Write message on UART sprintf(buffer, "%12e", ww); // Format ww and store it to buffer UART0_Write_Text("rne format:"); // Write message on UART UART0_Write_Text(buffer); // Write buffer on UART sprintf(buffer, "%12f", ww); // Format ww and store it to buffer UART0_Write_Text("rnf format:"); // Write message on UART UART0_Write_Text(buffer); // Write buffer on UART sprintf(buffer, "%12g", ww); // Format ww and store it to buffer UART0_Write_Text("rng format:"); // Write message on UART UART0_Write_Text(buffer); // Write buffer on UART }
What do you think about this topic ? Send us feedback!