-1

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);
        }
    }
}
fzsdi
  • 13
  • 1
  • 9
  • `#include ` ? – ryyker Dec 22 '20 at 19:44
  • 3
    Your C implementation may or may not come with this function. It is a [freestanding implementation](https://en.cppreference.com/w/cpp/freestanding) geared towards small embedded devices, so most of the standard library could be omitted. – n. m. could be an AI Dec 22 '20 at 19:47
  • @n.'pronouns'm. typically , if sprintf is omitted then `stdio.h` would not be provided at all (and conversely, if `stdio.h` is provided then it would typically contain the standard functions normally provided by that header). – M.M Dec 22 '20 at 20:25

1 Answers1

4

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.

mitchell
  • 298
  • 1
  • 11
  • now I'm getting this error: function argument #1 of type 'unsigned char[10]' is incompatible with required parameter of type 'flash unsigned char *' – fzsdi Dec 22 '20 at 20:01
  • 1
    @fzsdi can you try using `lcd_puts(buffer);` instead of `lcd_putsf(buffer);` – mitchell Dec 22 '20 at 20:14
  • @fzsdi did the development environment come with documentation? It should explain about flash memory versus RAM and so on – M.M Dec 22 '20 at 20:37
  • 1
    @fzsdi it is a ram vs flash issue. The way you declared the char array, it is stored in ram and not flash. The other printing function can only print flash variables. – mitchell Dec 22 '20 at 20:38