cprintfundefinedlcdcodevisionavr

Why am I getting undefined symbol 'sprintf' in CodeVisionAVR using C language?


I'm coding in CodeVision AVR using C, I want to count from 0 to 100 (Counter) and then display it on a LCD in Proteus. While choosing "Build All" in CodeVision, I get this error. I have no clue why.

undefined symbol 'sprintf'

The code:

#include <mega16.h>
#include <delay.h>
#include <alcd.h>
void main(void)
{
    int i;
    char buffer[10];
    lcd_init(16);
    while(1)
    {
        for(i=0;i<=100;i++)
        {
            lcd_clear();
            lcd_gotoxy(0,0);
            sprintf(buffer, "Time=%2d", i);
            lcd_putsf(buffer);
            delay_ms(100);
        }
    }
}

Solution

  • make sure that you have #include <stdio.h>

    Also use lcd_puts(buffer); instead of lcd_putsf(buffer);

    lcd_putsf() is the flash version of the lcd printing function. The way that you declared your character array, it is in ram and not flash, so you must use the other lcd printing function.