Why didn't all of you people write this yourselves, rich, experienced, employed, as opposed to me?
Why didn't Mikroelektronika's people solve this, if they even have those people who created the compiler now, I doubt they work there any more ?
You can create the function
int printf(const char *format, ...)
using the existing
signed int sprintf(char *wh, const code char *f,...);, the only thing my solution does not take into account is the help file does not say sprintf returns -1 if there is an error, so if your code expects only -1 and not 0 for an error you need to test if the sprintf returns -1 when there is error in the output... probably does, return value is signed int.
If you looked at the help file for the implemented sprintf function, you would have seen it has the most important features of the printf, the same syntax for parsing the format string, most of the time it would be compatible with the printf format string. You can't implement the printf as a wrapper function yourself, because the mikroC does not allow you to have multiple function definitions with various arguments, and also does not allow for an undefined number of parameters in a user function, also C language can not distinguish between nonstruct blank pointers runtime. But the
sprintf function does all this.
Now you define several
macros with parameters, for 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, however many of parameters you need, which replace the printf call with a sprintf call, followed by a UART1_Write_Text. I am talking about writing a macro for every number of arguments in a printf call you need. I have defined macros with parameters in mikroC, it works great, but you have to test how it works a little, the help file does not go into detail of exactly how, you need to try. Now you add a \n in between the sprintf command and the UART1_Write_Text command of the macro, which needs to be in a single line. And you have a compile time solution for this compatibility problem you all want solved. I will not write the code for you, I want you real professionals here to write the code, because if I know how to do it, you hard core professionals must know it too. Or am I the best coder here, having almost no experience?
This is how you define a macro
Code: Select all
#define macro_identifier(<arg_list>) <token_sequence>
the identifier is
Code: Select all
printf(format, arg1, ... a list of arguments );
the token sequence is the
Code: Select all
sprintf(string, format, arg1, ... a list of arguments );
then you write the line delimiter \n or /n, try it
, then you write the UART1_Write_Text(string); and press enter
and you declare the
or something in the new printf.c header file before the definition of printf macro.
Don't forget to
in the main() when you use this.
Did you get it, professionals from MikroElektronika, and the other professionals who really earn money for themselves with their coding?
I am kidding, I am sure this will work, try it. I give this info to all the people who have been mistreated by mikroC bugs and the lack of printf, free of charge.