Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
I'm trying to do this for my school, instead of searching for the account number to find the customer, I'm having to find the customer name instead..The usual strcmp ( customerNames[index], searchCustomer ) == 0 ) doesn't work on this. It seems that is only for one value, while this customerNames array that I have has 4 different preset names, plus whatever you add to it in run-time. Any help is appreciated ;)

//--Main Function
int main()
{
    int mainMenuSelection;
    int accountArray[SIZE] = {1202, 5841, 5644, 5481};
    double balanceArray[SIZE] = {450.23, 541.25, 1027.27, 108.50};
    char customerNames[SIZE][25] = {"George Washington", "John Smith", "Jane Smith", "Adam Smith"};

    int index;

    mainMenu(accountArray, balanceArray, customerNames);


    system("pause");
    return 0;
}
//--------------------------------------------------------------------------------



void searchByName ( int accountArray[], double balanceArray[], char customerNames[][25])
{



char searchCustomer;
    int index = 0, found = -1;
    double amount = 0;
    printf ("Enter the account to search for:");
    fflush ( stdin );
    scanf ("%[^\t\n]s", &searchCustomer);


    while ( index < SIZE )
    {
        if ( customerNames[index] == searchCustomer  )
        {
            found = index;
            break;
        }
        index++;
    }

    if ( found == -1 )
    {
        printf ("That account doesn't exist!\n\n");
        system("pause");
        bankerSide(accountArray, balanceArray, customerNames );
    }
    else
    {
        printf ("Here is the customer :\n");
        printf("\t%s\tAcc#%i\n", customerNames[index], accountArray[index]);
        system("pause");
        bankerSide(accountArray, balanceArray, customerNames );

    }
}
//--------------------------------------------------------------------------------
Posted
Updated 13-Jun-11 17:39pm
v2

1 solution

Try using strcmp()... there's a variety of different methods for comparing strings, but that's probably one of the simplest in concept.

There's other things to consider in the future though (that you should consider as a student):
- What happens with white space (before or after the first or last name)?
- What happens if caps aren't exactly in the same spot?

All string container classes have some sort of comparator, look them up so you can compare and contrast the different methods.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900