"memset" messing up my code

Hi, so i'm going to start with the code because i have no idea what's wrong

void entrerPassword() {
  int k=5;
  Passwordtemp = "";
  active = true;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" *** ALARM *** ");
  lcd.setCursor(0,1);
  lcd.print("Pass>");
      while(active) {
      key = pad.getKey();
      if (key != NO_KEY){
        if (key == '0' || key == '1' || key == '2' || key == '3' ||
            key == '4' || key == '5' || key == '6' || key == '7' ||
            key == '8' || key == '9' ) {
          Passwordtemp += key;
          lcd.setCursor(k,1);
          lcd.print("*");
          k++;
        }
      }
      if (k > 9 || key == '#') {
        Passwordtemp = "";
        k=5;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" *** ALARME *** ");
        lcd.setCursor(0,1);
        lcd.print("Pass>");
      }
      if ( key == '*') {
        if ( Passwordtemp == password ) {
          Alarmeactive = false;
          Activer = false;
          active = false;
          alarm_on=0;
          distanceinit=1;
          noTone(BUZZ);
          lcdinitiale = 0;
          memset(arr_duree_plus, 0, sizeof(arr_duree_plus));
          memset(arr_duree_moins, 0, sizeof(arr_duree_moins));
          memset(actu_arr_duree_plus, 0, sizeof(actu_arr_duree_plus));
          memset(actu_arr_duree_moins, 0, sizeof(actu_arr_duree_moins));
        }
        else if (Passwordtemp != password) {
          lcd.setCursor(0,1);
          lcd.print("INVALIDE");
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(" *** ALARM *** ");
          lcd.setCursor(0,1);
          lcd.print("Pass>");
          }}}}

before i added "memset" everything worked normally but when i add it the condition if ( Passwordtemp == password ) no longer works and i get password invalid even though the password is correct

What is the data type of the memset() target arrays ?

If you had posted a complete program there would be no need to ask

sorry i just thought the code was too long to post
it’s an integer array
here’s the full code (i know it’s not perfect i’m a beginner)

#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Servo.h>

int Trigger=A2;
int Echo=A1;
int BUZZ=A3;
long duree;
int distance, i;
int lcdinitiale =0;
int r=0;
String password="8426";
String Passwordtemp;
boolean active = false;
boolean Alarmeactive = false;
boolean Activer = false;
boolean Passwordcorrect;
boolean modechangerpass = false;
boolean passchange = false;
boolean changertemp=false;
boolean minuteschange =false;
boolean heurschange=false;
unsigned long Millisactuel;
unsigned long Millis;
unsigned long periode = 0;
int timer_h, timer_m;
int pos=0;
int d=0;
int arr_duree_plus [90];
int arr_duree_moins [90];
int actu_arr_duree_plus [90];
int actu_arr_duree_moins [90];
int alarm_on=0;
int distanceinit=1;
char key;

const byte ligne = 4;
const byte col = 3;
char keys[ligne][col] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte Pinligne[ligne] = {10, 9, 8, 1};
byte Pincol[col] = {13, 12, 11};
Keypad pad = Keypad( makeKeymap(keys), Pinligne, Pincol, ligne, col); 

const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

Servo servo;

void setup() { 
  servo.attach(A0);
  servo.write(pos);
  lcd.begin(16,2); 
  pinMode(BUZZ,OUTPUT);
  pinMode(Trigger,OUTPUT);
  pinMode(Echo,INPUT);
  Millis = millis();
}
void loop() {
  if (Alarmeactive) {
    lcd.clear();
    int compte = 1;
    while (compte != 0) {
      lcd.setCursor(0,1);
      lcd.print(compte);
      compte--;
      tone(BUZZ, 700, 100);
      delay(1000);
    }
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Alarme activee!");
    Alarmeactive = false;
    Activer = true;
    Millisactuel = millis();    
  }
  if (Activer == true){
    if (distanceinit==1){
      distanceinitiale();
    }
    distanceactuel();
    if (periode>0){
  if (Millisactuel - Millis >= periode){
    Alarmeactive = false;
    Activer = false;
    lcdinitiale = 0;
    distanceinit=1;
    Millis = Millisactuel;
  }}
      if (alarm_on==1) {
        tone(BUZZ, 1000);
        lcd.clear();
        entrerPassword();
      }
    }
  if (!Activer) {
    if (lcdinitiale == 0 ){
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("   1-Activer");
      lcd.setCursor(0,1);
      lcd.print("2-Timer 3-Changer");
      lcdinitiale = 1;
    }
    key = pad.getKey();
     if (key =='1'){
      tone(BUZZ, 1000, 200);
      Alarmeactive = true;            
    }
    else if (key =='3') {
      lcd.clear();
      int i=1;
      tone(BUZZ, 2000, 100);
      Passwordtemp = "";
      lcd.setCursor(0,0);
      lcd.print("Current Password");
      lcd.setCursor(0,1);
      lcd.print(">");
      modechangerpass = true;
      passchange = true;   
      while(passchange) {      
      key = pad.getKey();
      if (key != NO_KEY){
        if (key == '0' || key == '1' || key == '2' || key == '3' ||
            key == '4' || key == '5' || key == '6' || key == '7' ||
            key == '8' || key == '9' ) {
         Passwordtemp += key;
         lcd.setCursor(i,1);
         lcd.print("*");
         i++;
         tone(BUZZ, 2000, 100);
        }
      }
      if (i > 5 || key == '#') {
        Passwordtemp = "";
        i=1;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("Current Password");
        lcd.setCursor(0,1);
        lcd.print(">"); 
      }
      if ( key == '*') {
        i=1;
        tone(BUZZ, 2000, 100);
        if (password == Passwordtemp) {
          Passwordtemp="";
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print("Set New Password");
          lcd.setCursor(0,1);
          lcd.print(">");
          while(modechangerpass) {
            key = pad.getKey();
            if (key != NO_KEY){
              if (key == '0' || key == '1' || key == '2' || key == '3' ||
                  key == '4' || key == '5' || key == '6' || key == '7' ||
                  key == '8' || key == '9' ) {
                Passwordtemp += key;
                lcd.setCursor(i,1);
                lcd.print("*");
                i++;
                tone(BUZZ, 2000, 100);
              }
            }
            if (i > 5 || key == '#') {
              Passwordtemp = "";
              i=1;
              tone(BUZZ, 2000, 100);
              lcd.clear();
              lcd.setCursor(0,0);
              lcd.print("Set New Password");
              lcd.setCursor(0,1);
              lcd.print(">");
            }
            if ( key == '*') {
              i=1;
              tone(BUZZ, 2000, 100);
              password = Passwordtemp;
              modechangerpass = false;
              passchange = false;
              lcdinitiale = 0;}
              }}}}}}}
void entrerPassword() {
  int k=5;
  Passwordtemp = "";
  active = true;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" *** ALARM *** ");
  lcd.setCursor(0,1);
  lcd.print("Pass>");
      while(active) {
      key = pad.getKey();
      if (key != NO_KEY){
        if (key == '0' || key == '1' || key == '2' || key == '3' ||
            key == '4' || key == '5' || key == '6' || key == '7' ||
            key == '8' || key == '9' ) {
          Passwordtemp += key;
          lcd.setCursor(k,1);
          lcd.print("*");
          k++;
        }
      }
      if (k > 9 || key == '#') {
        Passwordtemp = "";
        k=5;
        lcd.clear();
        lcd.setCursor(0,0);
        lcd.print(" *** ALARME *** ");
        lcd.setCursor(0,1);
        lcd.print("Pass>");
      }
      if ( key == '*') {
        if ( Passwordtemp == password ) {
          Alarmeactive = false;
          Activer = false;
          active = false;
          alarm_on=0;
          distanceinit=1;
          noTone(BUZZ);
          lcdinitiale = 0;
          memset(arr_duree_plus, 0, sizeof(arr_duree_plus));
          memset(arr_duree_moins, 0, sizeof(arr_duree_moins));
          memset(actu_arr_duree_plus, 0, sizeof(actu_arr_duree_plus));
          memset(actu_arr_duree_moins, 0, sizeof(actu_arr_duree_moins));
        }
        else if (Passwordtemp != password) {
          lcd.setCursor(0,1);
          lcd.print("INVALIDE");
          delay(2000);
          lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(" *** ALARM *** ");
          lcd.setCursor(0,1);
          lcd.print("Pass>");
          }}}}

void distanceinitiale(){
  for (pos=0;pos<=180;pos+=2){
  servo.write(pos);
  delay(15);
  digitalWrite(Trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trigger, LOW);
  duree = pulseIn(Echo, HIGH);
  distance = duree*0.034/2;
  arr_duree_plus [r] = distance;
  r++;}
  for (pos=180;pos>=0;pos-=2){
  servo.write(pos);
  delay(15);
  digitalWrite(Trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trigger, LOW);
  duree = pulseIn(Echo, HIGH);
  distance = duree*0.034/2;
  arr_duree_moins [d] = distance;
  d++;}
  distanceinit=0;
  }

void distanceactuel(){
  int u=0;
  int p=0;
  if (alarm_on==0){
  for (pos=0;pos<=180;pos+=2){
  servo.write(pos);
  delay(15);
  digitalWrite(Trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trigger, LOW);
  duree = pulseIn(Echo, HIGH);
  distance = duree*0.034/2;
  actu_arr_duree_plus [u] = distance;
  lcd.print(actu_arr_duree_plus [u]-arr_duree_plus [u]);
  if(actu_arr_duree_plus [u]-arr_duree_plus [u]>2 || actu_arr_duree_plus [u]-arr_duree_plus [u]<-2){
    pos=181;
    alarm_on=1;}
    u++;
  }}
  if (alarm_on==0){
  for (pos=180;pos>=0;pos-=2){
  servo.write(pos);
  delay(15);
  digitalWrite(Trigger, LOW);
  delayMicroseconds(2);
  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(Trigger, LOW);
  duree = pulseIn(Echo, HIGH);
  distance = duree*0.034/2;
  actu_arr_duree_moins [p] = distance;
  lcd.print(actu_arr_duree_moins [p]-arr_duree_moins [p]);
  if(actu_arr_duree_moins [p]-arr_duree_moins [p]>2 || actu_arr_duree_moins [p]-arr_duree_moins [p]< -2){
    pos=-1;
    alarm_on=1;}
    p++;}}
}

i had to remove a few things because the message exceeded the limit of 9000 characters

}}}}}}} Don’t you hate it when that happens?

What Arduino are you using? String is discouraged for use on Arduino due to memory fragmentation. Also the 4 arrays you are memset'ting are a total of 720 bytes. An Uno, for example, only has 2K of SRAM. SRAM has to contain your static allocations, variables, stack, and heap. You may be running out of memory.

Optimizing SRAM

I'm not going to go through your code completely, but in at least a couple of places you are using a variable to index those arrays, then incrementing the variable, but I don't see anywhere that you are testing to make sure the variable doesn't go past the end of the array. Just a suggestion for the future, avoid using single letters for variable names, makes it difficult to tell what the variable is intended to do, and nearly impossible to search for every place it is used.

i would love it if i could just delete those arrays completely after every loop and re-initiate them anyway i could do that instead of filling theme with zeros?

There should be no problem with using memset() as long as the parameters are correct and your code does not write outside of the array bounds anywhere. Testing array indices before writing to the array to prevent that would seem like a good idea

the arrays did go out of bounds and i fixed it after "david_2018" pointed it out, but the problem persists

So, post the code as it is now.
Don’t forget to auto-format it before posting.

turns out just removing the "int ++" fixed everything because it was overwriting the past value instead of filling the array don't even need the memset anymore thanks you all for the help