2

I'm writing a code and I can't use a String as parameter of a function, the Arduino keeps resetting. This is my original code thad do not works:

Serial.print(readLine("routes.txt", 1)); // calling the function

String readLine(String fileName, unsigned int lineNum)
{
  if (!SD.exists(fileName))
  {
    Serial.println("- " + fileName + " do not exists!");
    return ("FAILURE");
  }
[continue the code...]

This code works:

Serial.print(readLine(1)); // calling the function

String readLine(unsigned int lineNum)
{
  if (!SD.exists("routes.txt"))
  {
    Serial.println("- " + "routes.txt" + " do not exists!");
    return ("FAILURE");
  }
[continue the code...]

Anyone to help me?

1 Answers1

0

Try assigning the value "routes.txt" into a variable of type String first and then use this variable as a parameter when calling the method. The compiler might assume the value is a char-array instead of a String-value.