This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

customization of putchar function

I have made the new function putchar for redirect the output to LCD already. But by default, I also want to use this as output to serial port on the same program.
I do not understand how to use both output function in parallel or other way to switch between each other.
Please tell me if possible.
With my thanks.

Parents
  • And for good measure, you'd probably want to 'reset' putchar_fp back to putchar so that any subsequent calls to normal printf() used ser_putchar() as originally indended. So make that...

    int my_printf(char (* which_putchar_fp)(char), const char *format, ...)
    {
        int     ret_val;
        va_list ap;
    
        putchar_fp = which_putchar_fp;
    
        va_start(ap, format);
        ret_val = vprintf(format, ap);
        va_end(ap);
    
        putchar_fp = ser_putchar;
        return ret_val;
    }

Reply
  • And for good measure, you'd probably want to 'reset' putchar_fp back to putchar so that any subsequent calls to normal printf() used ser_putchar() as originally indended. So make that...

    int my_printf(char (* which_putchar_fp)(char), const char *format, ...)
    {
        int     ret_val;
        va_list ap;
    
        putchar_fp = which_putchar_fp;
    
        va_start(ap, format);
        ret_val = vprintf(format, ap);
        va_end(ap);
    
        putchar_fp = ser_putchar;
        return ret_val;
    }

Children