Hi I am trying to write a light weight printf style function.
I have got this far:
Code:
void println(const char *txData){
LOG(__PRETTY_FUNCTION__);
UARTPuts (LPC_UART0, txData);
}
void miniPrint(const char *format, ...)
{
unsigned int index = 0;
va_list argptr;
va_start(argptr, format);
while(format[index] != '\0')
{
if(format[index] == '%')
{
index++;
if(format[index] == '\0')
break;
switch(format[index])
{
case 'd':
send_int(va_arg(argptr, uint32_t));
break;
case 'c':
transmit(va_arg(argptr, uint32_t));
break;
case 's':
sendString(va_arg(argptr, char *));
break;
default:
println(&format[index]);
}
}
else {
println(&format[index]);
}
index++;
}
va_end(argptr);
}
(its for an embedded platform)
If I do:
Code:
miniPrint("hello\n");
in main, I get:
I understand why I think. When I am passing the reference to the array possion it is outputting everything up to the next /0. So my question is how do I stop it?
I dont have much choice as to how the output wants it:
Code:
void UARTPuts(LPC_UART_TypeDef *UARTx, const void *str)
Thats library code, so I dont want to change it. I.e I have to pass an address into println.
Thanks
Alex