简体   繁体   English

带有SD.h文件类型的`fprintf`

[英]`fprintf` with SD.h's File type

I'm using the SD.h library to write onto an SD card with the Arduino Uno . 我正在使用SD.h库用Arduino Uno写入SD卡。 I need to write out in a file a template string with some placeholder replaced by certain values, in the way of printf behaves. 我需要在文件中写出一个模板字符串,其中一些占位符由某些值替换,以printf行为的方式。 I would use the fprintf function, but when I tried this: 我会使用fprintf函数,但是当我尝试这个时:

File dataFile = SD.open("myfile.txt", FILE_WRITE);
fprintf(dataFile, "mynumber: %d\n", 100);

I got this error: 我收到了这个错误:

cannot convert 'File*' to '__file*' for argument '1' to 'int fprintf(__file*, const char*, ...)' 无法将参数'1'的'File *'转换为'__file *'为'int fprintf(__ file *,const char *,...)'

How can I manage this? 我该怎么办呢?

printf() makes your executable object ~1000 bytes larger, so you may not want to use it if size is a problem. printf()使您的可执行对象大1000字节,因此如果大小有问题,您可能不想使用它。

The fprintf is not intended to use with the SD.h so I think 我认为fprintf不适用于SD.h

The simple solution that comes into my mind is using sprintf to format your text then write it to the file with the println function 我想到的简单解决方案是使用sprintf格式化文本,然后使用println函数将其写入文件

File dataFile = SD.open("myfile.txt", FILE_WRITE);
char text[100];
sprintf(text,"My number: %d",yournumber);
dataFile.println(text);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM