Updating an integer array using a keypad

I have globally declared array a={1,2,2,3,4}
i need to update this array using input from the keypad.I’ve done this by calling the function update from my void loop().
But no matter what i do i cant update it.Whats wrong?
Thanks.I’m new to arduino.
This is my code:

int update()    
{ int i=0;  
lcd.clear();  
lcd.print("Welcome");  
while(1){  
if(num=keypad.getKey())  
{ 
a[i]=num;  
lcd.clear();  
lcd.print('*');  
i=i+1;  
if(i==4)   
goto no;  

}  
       }  
no:  
return 0;           
}

Can anyone suggest how to do this.
I know that its not getting updated i’ve checked it.
its not getting inside the if statements(If it does then the lcd should print a ‘*’ )
i’m using proteus for testing as of now.

hard.ino (2.83 KB)

Please post your whole program and put it in code tags to avoid it turning into italic gibberish like your original post. How do you know that the array is not updated ?

a[i]=num;
a[i]=num;

I assume that was in the original code, hence the italics, but I bet that won't end up with the results required because the number read from the keypad is likely a char not a byte.

UKHeliBob: Please post your whole program and put it in code tags to avoid it turning into italic gibberish like your original post. How do you know that the array is not updated ?

know that its not getting updated i've checked it. its not getting inside the if statements(If it does then the lcd should print a '*' )

Hackscribble: I've used a[i]=num; only

UKHeliBob: a[i]=num;

I assume that was in the original code, hence the italics, but I bet that won't end up with the results required because the number read from the keypad is likely a char not a byte.

Yeah that was in the original code. So in what other way can i do this? Thanks

First, you can reformat your code to a standard format by pressing Ctrl-T in the IDE. That helps us to read your code. Second, a Serial.read() call reads a single byte at a time, not everything entered. If you want to read multiple digit characters with one call, read up on Serial.readBytesUntil(). Third, a switch with a case labeled as 49 isn't nearly as clear as a case labeled '1'. Better still, using the statement:

   int number;
   // more code...
      number = Serial.read() - '0';  // Subtract ASCII zero. So, for a '1' digit char: number = 49 - 48 - 1
                                     // which means number is now 1, not a character.

which ends up with number being an int value rather than a digit char.