Sprint Library
The mikroC PRO for AVR 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 |
void 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 |
void 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 |
void 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.
double ww = -1.2587538e+1; char buffer[15]; void main(){ UART1_Init(9600); // Initialize UART module at 4800 bps Delay_ms(10); UART1_Write_Text("Floating point number representation"); // Write message on UART sprintf(buffer, "%12e", ww); // Format ww and store it to buffer UART1_Write_Text("rne format:"); // Write message on UART UART1_Write_Text(buffer); // Write buffer on UART sprintf(buffer, "%12f", ww); // Format ww and store it to buffer UART1_Write_Text("rnf format:"); // Write message on UART UART1_Write_Text(buffer); // Write buffer on UART sprintf(buffer, "%12g", ww); // Format ww and store it to buffer UART1_Write_Text("rng format:"); // Write message on UART UART1_Write_Text(buffer); // Write buffer on UART }
What do you think about this topic ? Send us feedback!