gpt4 book ai didi

C18 sprintf() 给出语法错误

转载 作者:行者123 更新时间:2023-11-30 16:34:58 25 4
gpt4 key购买 nike

我的行似乎有语法错误

FSFILE *file; 

在添加 sprintf() 行后的以下代码中。代码一直有效,直到我添加了 char text、textresult 和 sprintf()。我似乎无法找出它出了什么问题。我正在使用 C18 编译器。该代码用于使用 SPI 将数据写入 SD 卡。 char txt[] 是使用温度传感器测量的值,例如:23,5。但我想为此添加更多文字。目标是每 5 分钟在 SD 卡上存储一次测量结果以及时间戳等。我正在使用 PIC18f27j53。

void writeFile()
{
unsigned char txt[]={ftc(result,0),ftc(result,1),0x2C,ftc(result,3)};
unsigned char text[]= "hello";
unsigned char textresult[];
sprintf(textresult, "%c%c", txt, text);
//unsigned char size = sizeof(result)-1;
FSFILE *file;
file = FSfopenpgm("DATA.TXT", "w");
if(file == NULL)while(1);
if(FSfwrite((void *) txt, 1, 4, file)!=4)while(1);
if(FSfclose(file)!=0)while(1);
}

最佳答案

sprintf(...) 移到声明变量的位置之后。

关于C18 sprintf() 给出语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49113214/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com