Thread: Comparing strings w/in structures

  1. #1
    Registered User
    Join Date
    Oct 2001

    Unhappy Comparing strings w/in structures

    Any insight will be most helpful.

    Basically, I'm trying to sort an array of structure type Employee by ssn which is an array of type char. My reasoning is to compare the strings and if string 1 is greater then string 2, swap Employee[1] with Employee[2].

    Does this make sense?

    Here's the part of the code and error messages I'm getting:
    void ssnSort (Employee[], int); //Sort by ssn

    ssnSort (Staff, numpeople);

    void ssnSort (Employee Staff, int num) {
    void swap (Employee[], Employee[]);
    int value = 0;
    for (int pass=0; pass!=num; pass++)
    for (int i=0; i!=num; i++) {
    /*175*/ value = strcmp (char Staff.ssn[i], char Staff.ssn[i+1]);
    if (value > 0) {
    /*177*/ swap ( Staff[i], Staff[i+1] );

    void swap (Employee *Employee1, Employee *Employee2) {
    Employee hold = *Employee1;
    *Employee1 = *Employee2;
    *Employee2 = hold;

    "", line 175: Error: Could not find a match for std::strcmp(char, char).
    "", line 177: Error: The operation "Employee[int]" is illegal.
    "", line 177: Error: The operation "Employee[int]" is illegal.
    3 Error(s) detected.

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    To access elements of an array of Employees you should do -




    In your swap function you'll have to pass in the addresses -

    swap ( &Staff[i], &Staff[i+1] );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. comparing 2 strings with pointer
    By meriororen in forum C Programming
    Replies: 9
    Last Post: 05-22-2009, 07:37 PM
  2. Replies: 2
    Last Post: 04-29-2009, 10:13 AM
  3. Problem with comparing strings!
    By adrian2009 in forum C Programming
    Replies: 2
    Last Post: 02-28-2009, 10:44 PM
  4. comparing strings
    By infinitum in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2003, 12:10 PM
  5. Comparing Strings
    By Perica in forum C++ Programming
    Replies: 6
    Last Post: 02-12-2003, 11:41 PM