jeudi 11 janvier 2018

Even though array numbers match, it still comes back false

Hi I am currently having a problem with my program. When i enter a phone number char, and compare it with a different phone number char, the answer comes back false.

Here my function searches the "findContact" function for a exact number. The getTenDigitPhone is the function to get the phone number. I end up getting the * Contact NOT FOUND * regardless if it matches or not

void searchContacts(const struct Contact contact[], int size) {
    char phone[11];
    int searchIndexContact;
    printf("Enter the cell number for the contact: ");

    getTenDigitPhone(phone);
    searchIndexContact = findContactIndex(contact, size, phone);

    if (searchIndexContact > -1) {
        printf("\n");
        printf("Contact found:\n");
        displayContact(&contact[searchIndexContact]);


    }
    else {
        printf("*** Contact NOT FOUND ***\n");
    }
}

** Here is the getTenDigitPhone function

void getTenDigitPhone(char telNum[11])
{
    int needInput = 1;

    while (needInput == 1) {
        scanf("%10s", telNum);
        clearKeyboard();

        // (String Length Function: validate entry of 10 characters)
        if (strlen(telNum) == 10)
            needInput = 0;
        else
            printf("Enter a 10-digit phone number: ");
    }
}

And here is the findContactIndex (to find out if the numbers match)

int findContactIndex(const struct Contact contacts[], int size, const char cellNum[])
{

    int i;
    int value = 0;
    for (i = 0; i < size; i++) {
        if (contacts[i].numbers.cell ==  cellNum);{
            printf(" %s    %s",contacts[i].numbers.cell , cellNum);
            value == 1;

        }

    }

    if (value == 1) {
        return value;
    }
    if (value == 0) {
        return -1;
    }

}

Aucun commentaire:

Enregistrer un commentaire