为什么我在使用 C 语言的 CodeVisionAVR 中得到未定义的符号“sprintf”?

fzs*_*sdi 0 c printf lcd undefined codevisionavr

我正在使用 C 在 CodeVision AVR 中进行编码,我想从 0 数到 100(计数器),然后将其显示在 Proteus 的 LCD 上。在 CodeVision 中选择“全部构建”时,出现此错误。我不知道为什么。

未定义符号 'sprintf'

编码:

#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);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

mit*_*ell 5

确保你有 #include <stdio.h>

也使用lcd_puts(buffer);代替lcd_putsf(buffer);

lcd_putsf()是lcd打印功能的flash版本。您声明字符数组的方式是在 ram 中而不是在 flash 中,因此您必须使用其他 lcd 打印功能。