Compiler Error "error: 'strlen' was not declared in this scope"

Hello, I have already made a program that uses a 4v4 matrix keypad to edit four separate strings of numbers and then add them all together when requested. The answers all all printed to the serial monitor. In order to learn how to make a library, using some online sources, I attempted turning some of my code into library functions and write a new program that does the same thing, just using my newly made library.

The code reads:

#include <STRING.h>
#include <Keypad.h>

STRING string;

const byte rows = 4;                    //initializes the keypad
const byte cols = 4;
char keys [rows][cols] = {
 {'1','2','3','a'},
 {'4','5','6','b'},
 {'7','8','9','c'},
 {'*','0','#','d'}
};
byte rowPins[rows] = {22, 24, 26, 28};
byte colPins[cols] = {30, 32, 34, 36};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );  //makes the keymap for the keypad

void setup() {
  Serial.begin(9600);
}

void loop() {
  string.switcher();         //switches what string is being edited
  string.addToString();    //adds keys pressed to whatever string is currently being edited and prints current string
  string.total();              //converts strings to ints and adds/prints them to the serial monitor
}

The string library is the one I created, the keypad library was an already working library I imported, it was used in my original program as well. The error message I get when compiling reads:

In file included from C:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Stream.h:26,
                 from C:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino/HardwareSerial.h:28,
                 from C:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Arduino.h:195,
                 from C:\Users\Hunter\Documents\Arduino\libraries\Keypad/utility/Key.h:37,
                 from C:\Users\Hunter\Documents\Arduino\libraries\Keypad/Keypad.h:36,
                 from C:\Users\Hunter\Documents\Arduino\libraries\STRING/STRING.h:4,
                 from addtostring.ino:1:
C:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Print.h: In member function 'size_t Print::write(const char*)':
C:\Program Files\Arduino\arduino-1.5.2\hardware\arduino\avr\cores\arduino/Print.h:51: error: 'strlen' was not declared in this scope

If you wish to see the original programs or either library just ask.

try <string.h> instead of STRING.H, case matters

there's also no such thing as a STRING, only a String. Also, please read "Read this before posting a programming question ..." so you can learn how to make your posts look right

Using <string.h> did not work, I doubled checked and the library is named "STRING.h". And STRING is a thing when its a class name, the command "STRING string;" simply makes a class of my STRING library called string for use in the program.

If you wrote the STRING library it's possible there's an error in there. Post that one, too.

STRING.h:

#ifndef STRING_H
#define STRING_H
#include <Arduino.h>
#include <Keypad.h>



class STRING {
public:
        STRING();
        ~STRING();
        void switcher();
        void addToString();
        void total();
};

#endif

STRING.cpp:

#include "STRING.h"

STRING::STRING() {
    String stringA;
    String stringB;
    String stringC;
    String stringD;
    char x;
    float a;
    float b;
    float c;
    float d;
}

STRING::~STRING() {}

void STRING::switcher() {
  char key = keypad.getKey();
  switch(key) {
    case 'a':
      x = 'a';
      Serial.println();
      Serial.print("string A = ");
      Serial.print(stringA);
      break;
    case 'b':
      x = 'b';
      Serial.println();
      Serial.print("string B = ");
      Serial.print(stringB);
      break;
    case 'c':
      x = 'c';
      Serial.println();
      Serial.print("string C = ");
      Serial.print(stringC);
      break;
    case 'd':
      x = 'd';
      Serial.println();
      Serial.print("string D = ");
      Serial.print(stringD);
  }
}

void STRING::addToString() {
      if(x == 'a') {
    switch(key) {
    case '1':
      stringA += "1";
      Serial.print("1");
      break;
    case '2':
      stringA += "2";
      Serial.print("2");
      break;
    case '3':
      stringA += "3";
      Serial.print("3");
      break;
    case '4':
      stringA += "4";
      Serial.print("4");
      break;
    case '5':
      stringA += "5";
      Serial.print("5");
      break;
    case '6':
      stringA += "6";
      Serial.print("6");
      break;
    case '7':
      stringA += "7";
      Serial.print("7");
      break;
    case '8':
      stringA += "8";
      Serial.print("8");
      break;
    case '9':
      stringA += "9";
      Serial.print("9");
      break;
    case '0':
      stringA += "0";
      Serial.print("0");
      break;
    case '*':
      stringA = "";
      Serial.println();
      Serial.println("string A cleared");
      Serial.print("string A = 0");
    }
    }
   
   if(x == 'b') {
    switch(key) {
    case '1':
      stringB += "1";
      Serial.print("1");
      break;
    case '2':
      stringB += "2";
      Serial.print("2");
      break;
    case '3':
      stringB += "3";
      Serial.print("3");
      break;
    case '4':
      stringB += "4";
      Serial.print("4");
      break;
    case '5':
      stringB += "5";
      Serial.print("5");
      break;
    case '6':
      stringB += "6";
      Serial.print("6");
      break;
    case '7':
      stringB += "7";
      Serial.print("7");
      break;
    case '8':
      stringB += "8";
      Serial.print("8");
      break;
    case '9':
      stringB += "9";
      Serial.print("9");
      break;
    case '0':
      stringB += "0";
      Serial.print("0");
      break;
    case '*':
      stringB = "";
      Serial.println();
      Serial.println("string B cleared");
      Serial.print("string B = 0");
    }
  }
    
  if(x == 'c') {
    switch(key) {
    case '1':
      stringC += "1";
      Serial.print("1");
      break;
    case '2':
      stringC += "2";
      Serial.print("2");
      break;
    case '3':
      stringC += "3";
      Serial.print("3");
      break;
    case '4':
      stringC += "4";
      Serial.print("4");
      break;
    case '5':
      stringC += "5";
      Serial.print("5");
      break;
    case '6':
      stringC += "6";
      Serial.print("6");
      break;
    case '7':
      stringC += "7";
      Serial.print("7");
      break;
    case '8':
      stringC += "8";
      Serial.print("8");
      break;
    case '9':
      stringC += "9";
      Serial.print("9");
      break;
    case '0':
      stringC += "0";
      Serial.print("0");
      break;
    case '*':
      stringC = "";
      Serial.println();
      Serial.println("string C cleared");
      Serial.print("string C = 0");
    }
  }
  
  if(x == 'd') {
    switch(key) {
    case '1':
      stringD += "1";
      Serial.print("1");
      break;
    case '2':
      stringD += "2";
      Serial.print("2");
      break;
    case '3':
      stringD += "3";
      Serial.print("3");
      break;
    case '4':
      stringD += "4";
      Serial.print("4");
      break;
    case '5':
      stringD += "5";
      Serial.print("5");
      break;
    case '6':
      stringD += "6";
      Serial.print("6");
      break;
    case '7':
      stringD += "7";
      Serial.print("7");
      break;
    case '8':
      stringD += "8";
      Serial.print("8");
      break;
    case '9':
      stringD += "9";
      Serial.print("9");
      break;
    case '0':
      stringD += "0";
      Serial.print("0");
      break;
    case '*':
      stringD = "";
      Serial.println();
      Serial.println("string D cleared");
      Serial.print("string D = 0");
    }
  }
}
    
void STRING::total() {  
      keypad.getKey();
      if(key == '#') {
      Serial.println();
      Serial.print("total = ");
      a = stringA.toInt();
      b = stringB.toInt();
      c = stringC.toInt();
      d = stringD.toInt();
      Serial.println(a + b + c + d);
    }
}

You may want to re-read the article about how to create a library. Your member variables need to be declared within the class definition in the .h file

Could you throw me an example on how that would look?

Move all the declarations in your constructor to a private section of your class definition in the .h file

"error: 'strlen' was not declared in this scope"

I don't get that error from your code:

sketch_apr20b:4: error: 'STRING' does not name a type
sketch_apr20b:17: error: 'Keypad' does not name a type
sketch_apr20b.ino: In function 'void loop()':
sketch_apr20b:24: error: 'string' was not declared in this scope

That is probably because you don't have the actual libraries. When it says "'STRING' does not name a type" and "'Keypad' does not name a type" that seems to tell me that it's not connecting them to the libraries. In which case, you wouldn't get far enough to get the error code I got.

Your whole library is a complete mess, I am not supprised the compiler can't make heads or tails of it.

(1) <string.h> is a system library, and calling so anything "STRING.h" is just likely to cause confusion.
(2) You don't declare class variables in the constructor, you do it in the class definition:

class STRING {
    String stringA;
   ...

(3) the instance 'keypad' does not exist in your library, it was declared in your main sketch. Trying to using keypad.getKey() in your library is just plain wrong. You could perhaps pass a pointer to the keypad instance to each of the functions which use it.

(4) you have used the variable 'key' in both addString() and total(), and yet it is declared in neither of them, nor is it declared as a class variable - in otherwords, it doesn't exist.

Fixing all of those, the problem goes away.

The error message you are getting is simply either Arduino, the preprocessor, or the compiler getting confused between your STRING.h and the C standard libraries string.h. Renaming the library gets rid of that message.

I haven't bothered to try and work out what the library is supposed to do and whether or not it does that, but this at least compiles:
.h

#ifndef ImNotCalledString_H
#define ImNotCalledString_H
#include <Arduino.h>
#include <Keypad.h>



class ImNotCalledString {
    String stringA;
    String stringB;
    String stringC;
    String stringD;
    char key;
    char x;
    float a;
    float b;
    float c;
    float d;
public:
        void switcher(Keypad* keypad);
        void addToString(Keypad* keypad);
        void total(Keypad* keypad);
};

#endif

.cpp

#include "ImNotCalledString.h"

void ImNotCalledString::switcher(Keypad* keypad) {
  key = keypad->getKey();
  switch(key) {
    case 'a':
      x = 'a';
      Serial.println();
      Serial.print("string A = ");
      Serial.print(stringA);
      break;
    case 'b':
      x = 'b';
      Serial.println();
      Serial.print("string B = ");
      Serial.print(stringB);
      break;
    case 'c':
      x = 'c';
      Serial.println();
      Serial.print("string C = ");
      Serial.print(stringC);
      break;
    case 'd':
      x = 'd';
      Serial.println();
      Serial.print("string D = ");
      Serial.print(stringD);
  }
}

void ImNotCalledString::addToString(Keypad* keypad) {
      if(x == 'a') {
    switch(key) {
    case '1':
      stringA += "1";
      Serial.print("1");
      break;
    case '2':
      stringA += "2";
      Serial.print("2");
      break;
    case '3':
      stringA += "3";
      Serial.print("3");
      break;
    case '4':
      stringA += "4";
      Serial.print("4");
      break;
    case '5':
      stringA += "5";
      Serial.print("5");
      break;
    case '6':
      stringA += "6";
      Serial.print("6");
      break;
    case '7':
      stringA += "7";
      Serial.print("7");
      break;
    case '8':
      stringA += "8";
      Serial.print("8");
      break;
    case '9':
      stringA += "9";
      Serial.print("9");
      break;
    case '0':
      stringA += "0";
      Serial.print("0");
      break;
    case '*':
      stringA = "";
      Serial.println();
      Serial.println("string A cleared");
      Serial.print("string A = 0");
    }
    }
   
   if(x == 'b') {
    switch(key) {
    case '1':
      stringB += "1";
      Serial.print("1");
      break;
    case '2':
      stringB += "2";
      Serial.print("2");
      break;
    case '3':
      stringB += "3";
      Serial.print("3");
      break;
    case '4':
      stringB += "4";
      Serial.print("4");
      break;
    case '5':
      stringB += "5";
      Serial.print("5");
      break;
    case '6':
      stringB += "6";
      Serial.print("6");
      break;
    case '7':
      stringB += "7";
      Serial.print("7");
      break;
    case '8':
      stringB += "8";
      Serial.print("8");
      break;
    case '9':
      stringB += "9";
      Serial.print("9");
      break;
    case '0':
      stringB += "0";
      Serial.print("0");
      break;
    case '*':
      stringB = "";
      Serial.println();
      Serial.println("string B cleared");
      Serial.print("string B = 0");
    }
  }
    
  if(x == 'c') {
    switch(key) {
    case '1':
      stringC += "1";
      Serial.print("1");
      break;
    case '2':
      stringC += "2";
      Serial.print("2");
      break;
    case '3':
      stringC += "3";
      Serial.print("3");
      break;
    case '4':
      stringC += "4";
      Serial.print("4");
      break;
    case '5':
      stringC += "5";
      Serial.print("5");
      break;
    case '6':
      stringC += "6";
      Serial.print("6");
      break;
    case '7':
      stringC += "7";
      Serial.print("7");
      break;
    case '8':
      stringC += "8";
      Serial.print("8");
      break;
    case '9':
      stringC += "9";
      Serial.print("9");
      break;
    case '0':
      stringC += "0";
      Serial.print("0");
      break;
    case '*':
      stringC = "";
      Serial.println();
      Serial.println("string C cleared");
      Serial.print("string C = 0");
    }
  }
  
  if(x == 'd') {
    switch(key) {
    case '1':
      stringD += "1";
      Serial.print("1");
      break;
    case '2':
      stringD += "2";
      Serial.print("2");
      break;
    case '3':
      stringD += "3";
      Serial.print("3");
      break;
    case '4':
      stringD += "4";
      Serial.print("4");
      break;
    case '5':
      stringD += "5";
      Serial.print("5");
      break;
    case '6':
      stringD += "6";
      Serial.print("6");
      break;
    case '7':
      stringD += "7";
      Serial.print("7");
      break;
    case '8':
      stringD += "8";
      Serial.print("8");
      break;
    case '9':
      stringD += "9";
      Serial.print("9");
      break;
    case '0':
      stringD += "0";
      Serial.print("0");
      break;
    case '*':
      stringD = "";
      Serial.println();
      Serial.println("string D cleared");
      Serial.print("string D = 0");
    }
  }
}
    
void ImNotCalledString::total(Keypad* keypad) {  
      key = keypad->getKey();
      if(key == '#') {
      Serial.println();
      Serial.print("total = ");
      a = stringA.toInt();
      b = stringB.toInt();
      c = stringC.toInt();
      d = stringD.toInt();
      Serial.println(a + b + c + d);
    }
}

.ino

#include <ImNotCalledString.h>
#include <Keypad.h>

const byte rows = 4;                    //initializes the keypad
const byte cols = 4;
char keys [rows][cols] = {
 {'1','2','3','a'},
 {'4','5','6','b'},
 {'7','8','9','c'},
 {'*','0','#','d'}
};
byte rowPins[rows] = {22, 24, 26, 28};
byte colPins[cols] = {30, 32, 34, 36};

Keypad _keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );  //makes the keymap for the keypad
ImNotCalledString string;



void setup() {
  Serial.begin(9600);
}

void loop() {
  string.switcher(&_keypad);         //switches what string is being edited
  string.addToString(&_keypad);    //adds keys pressed to whatever string is currently being edited and prints current string
  string.total(&_keypad);              //converts strings to ints and adds/prints them to the serial monitor
}

It does indeed compile now. The only issue I'm having is the program isn't doing what it's supposed to. But this could also be because I don't have my mega with me so I'm having to use the serial in/out pins on the Uno (0 and 1) because that is the only place that has 8 pins in a row. I'll be able to check it with my Mega 2560 R3 on Tuesday.