user11174: In the example below, I have two functions that write numbers to two different files on an SD card. I'm using the SdFat library. 
Is there any way I can combine the two functions into one, so that I can call (for example): writeToFile(int t, FileName "filename1.txt");?
In the example below, to write a value to the "temperature.txt" file, I would like to be able to call: writeToFile(7, "temperature.txt"); In my sketch I have about a dozen functions that are writing to a dozen different files, so it would be very handy to be able to combine them into one function.
I think the main part I'm stuck on is I have no idea what the filename variable would be, or how to pass the filename to the function.
#include <SdFat.h>
SdFat sd;

void setup() {
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }

  setTemperature(7);
  setFanSpeed(4);
}

void setTemperature(int t) {
  SdFile rdfile("temperature.txt", O_WRITE);
  rdfile.rewind();
  rdfile.println(t);
  rdfile.close();
}

void setFanSpeed(int t) {
  SdFile rdfile("fanspeed.txt", O_WRITE);
  rdfile.rewind();
  rdfile.println(t);
  rdfile.close();
}


user368: String literals are of type const char *. Ordinary char *s can be passed to it though; the const means that the compiler will make sure that the function doesn't attempt to change the contents.
void setFileParameter(const char *filename, int value)
{
   ...
}


11174: <p>In the example below, I have two functions that write numbers to two different files on an SD card. I'm using the <a href="https://github.com/greiman/SdFat" rel="nofollow">SdFat library</a>. </p>

<p>Is there any way I can combine the two functions into one, so that I can call (for example): <code>writeToFile(int t, FileName "filename1.txt");</code>?</p>

<p>In the example below, to write a value to the "temperature.txt" file, I would like to be able to call: <code>writeToFile(7, "temperature.txt");</code> In my sketch I have about a dozen functions that are writing to a dozen different files, so it would be very handy to be able to combine them into one function.</p>

<p>I think the main part I'm stuck on is I have no idea what the filename variable would be, or how to pass the filename to the function.</p>

<pre><code>#include &lt;SdFat.h&gt;
SdFat sd;

void setup() {
  if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
    sd.initErrorHalt();
  }

  setTemperature(7);
  setFanSpeed(4);
}

void setTemperature(int t) {
  SdFile rdfile("temperature.txt", O_WRITE);
  rdfile.rewind();
  rdfile.println(t);
  rdfile.close();
}

void setFanSpeed(int t) {
  SdFile rdfile("fanspeed.txt", O_WRITE);
  rdfile.rewind();
  rdfile.println(t);
  rdfile.close();
}
</code></pre>
 368: <p>String literals are of type <code>const char *</code>. Ordinary <code>char *</code>s can be passed to it though; the <code>const</code> means that the compiler will make sure that the function doesn't attempt to change the contents.</p>

<pre><code>void setFileParameter(const char *filename, int value)
{
   ...
}
</code></pre>
