I’m using the SD.h library to write onto an SD card with the Arduino Uno. I need to write out in a file a template string with some placeholder replaced by certain values, in the way of printf behaves. I would use the fprintf function, but when I tried this:
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*, …)’
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.
The
fprintfis not intended to use with the SD.h so I thinkThe simple solution that comes into my mind is using sprintf to format your text then write it to the file with the println function