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

我正在使用 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);
        }
    }
}

回答

确保你有 #include <stdio.h>

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

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


以上是为什么我在使用C语言的CodeVisionAVR中得到未定义的符号“sprintf”?的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>