about toInt() command

i need a little help about the comands of toInt(); with arrays. im a noob in field of programming, i like to learn more things about programming. it really helps me if someone give me some more simple examples of it..by the way i already read some example of it, but i need more reference ty.

What kind of arrays?

And you better forget that Strings (capital S) exist. They are convenient but can cause difficult to trace bugs in your software. Use so-called c-strings instead and functions like atoi.

You should avoid using Strings on Arduino, as they cause memory problems and program crashes.

A much better alternative is atoi() or atol(), which converts c-strings (zero terminated ASCII character arrays) into integers.

Describe what you really want to do and we can help.

ty for commends...

one of my materials using keypad, im finding a way how to a char to convert to int in using toInt(); and this use it to store it the arrays.

a = (char)whichKey; // this is where my error are..

No error there, a will be a single character. It is not a c-string or a String.

Tell us which keyboard library you are using, or explain exactly which characters are returned.

Also, please read the "How to use this forum" post so that you can post code properly, using code tags.

Edit: you removed the code fragments from an earlier version of the post. DON'T USE toInt().

sorry it's my first time here.using this forum. :confused:

here my code:

String a= "";
int b=0;
 char whichKey = myKeypad.waitForKey();

 while(whichKey!= '#'){
 a[b] = (char)whichKey;
 lcd.print(a[b].toInt());
 b++;
 }

Please identify which keypad library you are using and where you downloaded it.

There are many problems with that simple bit of code, and that is not all the code. Always post ALL the code.

Start with the simple examples that come with the library, and make sure that they work and that you understand them completely, before trying something on your own.

while (whichKey != '#')
{
  a[b] = (char)whichKey;
  lcd.print(a[b].toInt());
  b++;
}

Can the condition to exit this while loop ever occur because whichKey is never updated within it.
Whatever the value of whichKey when the while loop starts it will never be changed.

String a= "";
int b=0;
 char whichKey = myKeypad.waitForKey();

 while(whichKey!= '#'){

 a[b] = (char)whichKey;

 lcd.print(a[b].toInt()); //this where my error.

 b++;

a[b] = "";
 }

this my error says:
request for member 'toInt' in 'a.String::operator[](((unsigned int)b))', which is of non-class type 'char'

it's liitle too confusing.

here my full code:

im using 4 x4 keypad

#include <LiquidCrystal.h> //include LCD library (standard library)
#include <Keypad.h> //include keypad library - first you must install library (library link in the video description)



#define redLED 10 //define the LED pins
#define greenLED 11

char* password ="1234"; //create a password
int pozisyon = 0; //keypad position




const byte rows = 4; //number of the keypad's rows and columns
const byte cols = 4;

char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad

  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad
byte colPins [cols] = {5, 6, 7, 8};

Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols);

LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7)

void setup(){

  lcd.begin(16, 2);
  pinMode(redLED, OUTPUT);  //set the LED as an output
  pinMode(greenLED, OUTPUT);
  setLocked (true); //state of the password


}

void loop(){

  char whichKey = myKeypad.getKey(); //define which key is pressed with getKey
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("    Welcome");
  lcd.setCursor(0, 1);
  lcd.print(" Enter Password");

  if(whichKey == '*' || whichKey == 'A' ||       //define invalid keys
  whichKey == 'B' || whichKey == 'C' || whichKey == 'D'){

    pozisyon=0;
    setLocked (true);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("  Invalid Key!");
    delay(1000);
    lcd.clear();
  }
  if(whichKey == password [pozisyon]){

    pozisyon ++;
  }
  if(pozisyon == 4){ 
    
    setLocked (false);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("*** Verified ***");
    delay(3000);
    lcd.clear();
systemfunction();

  }
  delay(100);
}


void systemfunction(){
  
  
   lcd.setCursor(0,0);
 lcd.print("Pls Enter your");
  lcd.setCursor(0,1);
  lcd.print("options:");
  delay(1000);
  lcd.setCursor(0,0);
  lcd.print ("Bill to coins[1]");
  lcd.setCursor(0,1);
  lcd.print ("Coins to Bill[2]");
  delay(1000);
  lcd.clear();
  
char whichKey = myKeypad.waitForKey();

 if(whichKey == '1'){
  lcd.setCursor(0,0);
  lcd.print("Pls Enter Number");
  lcd.setCursor(0,1);
  lcd.print("of Coins:");
  
String a= "";
int b=0;
 char whichKey = myKeypad.waitForKey();

 while(whichKey!= '#'){


 a[b] = (char)whichKey;//this is where my error is.

 lcd.print(a[b].toInt());

 b++;

a[b] = "";
 }


 }

 
 
 else if(whichKey == '2'){
   lcd.print("love you");
   delay(1000);
 }
  else{
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Invalid Key!");
    delay(1000);
    lcd.clear();
    systemfunction();
  }

  

    
  
}
void setLocked(int locked){
  if(locked){
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
    }
    else{
      digitalWrite(redLED, LOW);
      digitalWrite(greenLED, HIGH);
    }
  }

request for member 'toInt' in 'a.String::operator[](((unsigned int)b))', which is of non-class type 'char'

You are trying to use the String toInt() function with a char variable, hence the error message.

You may practice this tutorial to get an idea on how data are entered from a Keypad in the form of ASCII Codes. After that, you may create example to understand how the ASCII codes (for the integer digits only: 0 to 9) could be converted into integer using atoi() and toInt() functions/methods.

Figure-1: Connection diagram among UNO, 4x4 Keypad, and I2CLCD

(1) Collect 4x4 Keypad and connect it with the UNO as per Fig-1.
(2) Collect I2CLCD and connect with the UNO as per Fig-1.
(3) Write a small program to test the I2CLCD to show the message Forum in the middle of Top Line. Save the program as keypad-1.
(4) Write program to scan keypad; show on LCD the label of the key that is pressed down; save the ASCII codes of the pressed down key in a character array. Save the program as keypad-2.

#include<Keypad.h>
#include<LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

const byte rows = 4;   //four rows
const byte cols = 4;  //four columns
char storage[5];      //to store four key's ASCII code + null-byte                
int arrayTracker = 0;

char keys[rows][cols] = {   //2-dimensional array contains ASCII codes for the labels of Keys
                          {'1','2','3','a'},
                          {'4','5','6','b'},
                          {'7','8','9','c'},
                          {'*','0','#','d'}
                        };

byte rowPins[rows] = {9,8,7,6};    //R1R2R3R4 connection Pin = 9876
byte colPins[cols] = {5,4,3,2};     //C1C2C3C4 connection Pin = 5432

Keypad keypad = Keypad(makeKeymap(keys),rowPins,colPins,rows,cols);  //Library Function
void setup()
{
 lcd.init();
 lcd.backlight();
 lcd.setCursor(0, 0);       //cursor position
 lcd.print("Enter Code:");
}

void loop()
{
  char input = keypad.getKey();  //scan keypad
  if(input != 0x00)        //if scan code is non-zer0
  {
    storage[arrayTracker] = input;   //store the ASCII code of the lable of key in array
    lcd.setCursor(arrayTracker, 1);  //cursor position of Line-2 pointed by next key
    lcd.print(storage[arrayTracker]);//show the label of key in LCD
    arrayTracker++;                   //adjust next key position
   }
   
   if(arrayTracker == 4)
   {
      storage[arrayTracker] = 0x00; //4 keys are pressed; add null-byte in char array
      while (1)
        ;
   }
 }

(5) Compile and upload the program of Step-4.
(a) Observe that the message Enter Codes: has appeared on the Top Line of the LCD.
(b) Press 1. Check that 1 has appeared at DP0 position of the Bottom Line of LCD.
(c) Press 2 3 4. Check that 2 3 4 have appeared on the Bottom Line of LCD.
(d) Press 5. Check that 5 have not appeared on the LCD. This means that the program has been designed to accept only 4 digits (key strokes) from the keypad.

(6) In the program of Step-4, there is an array (char storage[5])which contains ASCII codes (0x31, 0x32, 0x33, 0x34) for the digits 0, 1, 2, 3. Now, explore the use of atoi() and toInt() functions to convert the content of this array into an integer value of 1234.

ty for effort i really appreciate it.. :). i will try it now