Garmaine Staff asked 1 year ago

I'm trying to write a function that takes an array of structs and will sort the elements of the array alphabetically by accessing the first data member. I'm struggling to get the code to distinguish between when I'm referring to a data member versus initializing the size of an array. For example, the following code

void selectionSort(struct A[], int size)
    int mindex;

    for (int ct1 = 0; ct1 < size - 1; ct1++)
        mindex = ct1;
        for (int ct2 = ct1 + 1; ct2 < size; ct2++)
            if (A[ct2].state < A[mindex].state)
                mindex = ct2;
        swap(A[mindex], A[ct1]);

complains that ct2 is not constant, when I'm clearly using it as an index. How would I get this to run correctly? That is, how can I get it to compare data members in their respective indices rather than think I'm initializing the size of a struct variable?

Edit The error message I am receiving is expression must have a constant value for the variable ct2.