Trying to pass structure array to function

diet.tonic_at_club.soda
Date: 01/29/04


Date: Thu, 29 Jan 2004 20:37:49 GMT

I keep getting a "pointer/array" required when I try to compile this, in the
sortChar function. I"ve tried a couple of different ways to do this, and I
keep getting hamstring. Any help?

#include <iostream>
#include <stdlib.h>
using namespace std;

struct charstr
{
    char inchar;
    int count;
};

void sortChar(charstr);

int main()
{

    int ASC_a = 97; // ASCII code for letter 'a'
    charstr unsortedChar[26];// holds initial input.
    charstr ptrChar;
    char input; // character that is input

    ptrChar = unsortedChar[0];
    bool finished; // flag that input has received a '.'
    finished = false;

    for (int a = 0; a < 26; a++)
    {
        unsortedChar[a].count = 0;
        unsortedChar[a].inchar = ' ';
    }

    cout << "Enter some characters. " << endl;
    cout << "Non-alpha characters will be ignored" << endl;
    cout << "Processing will stop when you enter a period." << endl;
    cout << "Enter a character: ";
    cin >> input;
    while (!finished)
    {

        if (isalpha(input))
        {
            unsortedChar[tolower(input) - ASC_a].inchar = tolower(input);
            unsortedChar[tolower(input) - ASC_a].count++;
        }

        else if (input == '.')
        {
            finished = true;
        }

        if (!finished)
        {
            cout << "Enter a character: ";
            cin >> input;
        }

    };

    for (int a = 0; a < 26; a++)
        if (unsortedChar[a].count > 0)
        {
            cout << unsortedChar[a].inchar << " " << unsortedChar[a].count
<< endl;
        }

    sortChar(ptrChar);

    for (int a = 0; a < 26; a++)
        if( unsortedChar[a].count > 0)
        {
            cout << unsortedChar[a].inchar << " " << unsortedChar[a].count
<< endl;
        }

    system("PAUSE");
    return 0;
};

void sortChar(charstr thisUnsortedChar)
//*******************************************************************
// Function sortChar(): The information in the structure will then be
// sorted in decreasing order by number of times
// that character was input. A selection sort
// will be used for that purpose.
//
// Parameters: thisUnsortedChar - pointer to a charstr structure
// variable.
// returns a sorted structure.
//*******************************************************************

{

charstr holdchar;
int passcount;
int searchindex;
int maxindex;

    for (passcount = 0; passcount < 26 - 1; passcount++)
    {
        maxindex = passcount;

        for (searchindex=passcount + 1; searchindex < 26; searchindex++)
        {

            if (thisUnsortedChar[searchindex].count >
thisUnsortedChar[maxindex].count)
                maxindex = searchindex;

        }

     holdchar = thisUnsortedChar[maxindex];
     thisUnsortedChar[maxindex] = thisUnsortedChar[passcount];
     thisUnsortedChar[passcount] = holdchar;

    }
    return thisUnsortedChar;
}