Adding To An Array

So I'm trying to do a fingerprint project and my teacher wants it to take attendance. Each student will have an ID and scan the fingerprint sensor to get their ID number added to the array. The teacher ID is 99 and will pull up the array to see which students show up. I use my thumb as ID 1 than the teacher scan their thumb, but the array keeps displaying 0's.

int attnd_lst[5] = {0, 0, 0, 0, 0};
  int i;
  int a = 0;
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (finger.fingerID != 99){
    attnd_lst[a] = {finger.fingerID};
    a = a + 1;
    return attnd_lst;
    }
  else{
    Serial.println("Hi");
    for (i = 0; i < 5; i++){
      Serial.println(attnd_lst[i]);
       }
    }/code]

If anyone can help me or need me to go in greater depth please ask.

I can't tell from this code fragment. Is this a part of another function or part of the loop() function? It would help greatly if you posted your entire sketch.

The following code looks suspicious since I don't know to whom you are returning attnd_list to. You are returning a pointer to attnd_list which is on the stack and will not be valid upon return.

Post all the code.

#include <Adafruit_Fingerprint.h>


SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup()  
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit finger detect test");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  delay(5);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }

  finger.getTemplateCount();
  Serial.print("Sensor contains "); Serial.print(finger.templateCount); Serial.println(" templates");
  Serial.println("Waiting for valid finger...");
}

void loop()                     // run over and over again
{
  getFingerprintIDez();
  digitalWrite(12, HIGH);
  delay(50);
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence); 

  return finger.fingerID;
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  
  // found a match!
  int attnd_lst[5] = {0, 0, 0, 0, 0};
  int i;
  int a = 0;
  Serial.print("Found ID #"); Serial.print(finger.fingerID); 
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (finger.fingerID != 99){
    attnd_lst[a] = {finger.fingerID};
    a = a + 1;
    return finger.fingerID;
    }
  else{
    Serial.println("Hi");
    for (i = 0; i < 5; i++){
      Serial.println(attnd_lst[i]);
       }
    }
   /*else if (finger.fingerID == 1){
    attnd_lst[0] = 1;
    }*/
  /*if (finger.fingerID == 1) {
      digitalWrite(12, LOW);
      digitalWrite(11, HIGH);
      delay(1000);
      digitalWrite(11, LOW);
      delay(1000);
      digitalWrite(12, HIGH);
      
    }
  else{
      Serial.println("Wrong Finger For The Light Show.");
      }*/
  return finger.fingerID; 
}

attnd_lst [] and a are local variables that are not persistent between calls to getFingerprintID(). make them global

You have the following defined as local variables in your getFingerprintIDez() function:

  int attnd_lst[5] = {0, 0, 0, 0, 0};
  int a = 0;

Make those global and your code will mostly work; however, you need to check the index to make sure you don't write past the end of the attnd_lst array or it will get really weird.

Thank you, it now works. I'm getting used to C++ and keep forgetting about these void setups and loops.

buncie:
Thank you, it now works. I'm getting used to C++ and keep forgetting about these void setups and loops.

Make sure you don't write past the end of the array. You'll get unexpected results, corrupted data, lockups, or crashes.