# char and string error's...

**URL:** <https://forum.arduino.cc/t/char-and-string-errors/387341>\
**Category:** Programming\
**Created:** [May 21, 2016, 8:47pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341 "2016-05-21T20:47:22Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![beall619](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/beall619/32/1170108_2.png) [@beall619](https://forum.arduino.cc/u/beall619)\
**Post date:** [May 21, 2016, 8:47pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/1 "2016-05-21T20:47:22Z")

</div>

```cpp
#include <Keypad.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(43, 45, 47, 49, 51, 53);
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {3, 2, 8, 9};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 
int PWC = 0;
String ENPA="";
String len="";
void setup(){
  lcd.begin(16, 2);
  Serial.begin(9600);
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);
}

void Flash(int ti){
  digitalWrite(13, HIGH);
  delay(ti);
  digitalWrite(13, LOW);
}

void loop(){
  lcd.setCursor(0, 0);
  lcd.print("Enter Password:");
  lcd.setCursor(0, 1);
  while(not PWC == 1){
  char customKey = customKeypad.getKey();
  if (customKey){
    lcd.print("#");
    tone(11, 1000, 50);
    Flash(50);
    ENPA += customKey;
    len = strlen(ENPA);
    Serial.println(len);
  }
}
}

```

I would like to have what im pressing added to a string so that each press adds to it.

Eventually when the string is 4 characters long it will be compared to a stored variable (a password), and then if it matches you will be notified.

Yes, i realize people have made code for this exact purpose.. But this is MY idea, lol.

Please help

Error-

**Enter\_pass:43: error: cannot convert 'String' to 'const char\*' for argument '1' to 'size\_t strlen(const char\*)'**  
\*\* len = strlen(ENPA);\*\*  
\*\* ^\*\*  
**exit status 1**  
**cannot convert 'String' to 'const char\*' for argument '1' to 'size\_t strlen(const char\*)'**

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [May 21, 2016, 9:55pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/2 "2016-05-21T21:55:37Z")

</div>

> I would like to have what im pressing added to a string so that each press adds to it.

C style strings (lowercase s) are arrays of chars terminated with a zero. Strings (capital S) are String objects.

```arduino
    ENPA += customKey;
    len = strlen(ENPA);

```

Here you are using strlen() which expects a string as a parameter but ENPA is a String. Either use Strings throughout or strings throughout. I am sure that there must be a function in the String library that returns the length of a String or alternatively keep track of its length with a counter variable.

In the longer term you would probably be better using strings and adding each character to the array as you go. This method is reckoned to use less memory and does not cause memory fragmentation.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 21, 2016, 10:08pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/3 "2016-05-21T22:08:30Z")

</div>

> I am sure that there must be a function in the String library that returns the length of a String

Yes, there is. For some strange reason, it is called length().

---

<div class="post-metadata">

**Author:** ![beall619](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/beall619/32/1170108_2.png) [@beall619](https://forum.arduino.cc/u/beall619)\
**Post date:** [May 24, 2016, 8:04pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/4 "2016-05-24T20:04:41Z")

</div>

length() only returns error

exit status 1  
'length' was not declared in this scope

---

<div class="post-metadata">

**Author:** ![KeithRB](https://avatars.discourse-cdn.com/v4/letter/k/74df32/32.png) [@KeithRB](https://forum.arduino.cc/u/KeithRB)\
**Post date:** [May 24, 2016, 8:08pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/5 "2016-05-24T20:08:19Z")

</div>

Try ENPA.length()

---

<div class="post-metadata">

**Author:** ![beall619](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/beall619/32/1170108_2.png) [@beall619](https://forum.arduino.cc/u/beall619)\
**Post date:** [May 26, 2016, 2:21am UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/6 "2016-05-26T02:21:50Z")

</div>

```cpp
#include <Keypad.h>
#include <LiquidCrystal.h>
#include <stdlib.h>
#include <string.h>
LiquidCrystal lcd(43, 45, 47, 49, 51, 53);
const byte ROWS = 4;
const byte COLS = 4;
char hexaKeys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

byte rowPins[ROWS] = {3, 2, 8, 9};
byte colPins[COLS] = {7, 6, 5, 4};
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); 
int PWC = 0;
String ENPA;
int len = 0;
char customKeyn[1];
void setup(){
  lcd.begin(16, 2);
  Serial.begin(9600);
  pinMode(11, OUTPUT);
  pinMode(13, OUTPUT);
}

void Flash(int ti){
  digitalWrite(13, HIGH);
  delay(ti);
  digitalWrite(13, LOW);
}

void loop(){
  lcd.setCursor(0, 0);
  lcd.print("Enter Password:");
  lcd.setCursor(0, 1);
  while(not PWC == 1){
  char customKey = customKeypad.getKey();
  if (customKey){
    char customKeyn = customKey;
    Serial.println(customKeyn);
    lcd.print("#");
    tone(11, 1000, 50);
    Flash(50);
    ENPA =  ENPA + customKeyn;
    len = ENPA.length();
    Serial.print("ENPA: ");
    Serial.print(ENPA);
    Serial.print(" -- ");
    Serial.println(len);
  }

  }
}

```

Well somehow it is working....  
Thank you guys!!!!!!!

Sorry about not replying. Finals all this week 😀

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:54pm UTC](https://forum.arduino.cc/t/char-and-string-errors/387341/7 "2021-05-05T21:54:30Z")

</div>

Closed on May 5, 2021, 9:54pm UTC


