0

I have an array of structs, and I just want to pass it to the function in order to sort it. What am I doing wrong, as far as passing the array of structs into the function? What errors are there in the prototype, call, and definition?

NOTE - I realize I have not initialized the array of structs. In my actual code, the array has data from a text file in it. That is not relevant to the question I am asking. So please do not comment about not having anything in the array.

Here is a little sample of code that I can't get to work:

#include <iostream>
using namespace std;

struct checkType
{
    char date[12];
    char checkNum[8];
    float amount;
};

void bubbleSort(checkType, const int);

int main()
{
    const int NUM = 5;
    checkType checkArray[NUM];

    bubbleSort(checkArray, NUM);

    return 0;
}

void bubbleSort(checkType array[], const int SIZE)
{
    bool swap;
    checkType temp;

    do
    {
        swap = false;

        for (int count = 0; count < (SIZE - 1); count++)
        {
            if (strcmp(array[count].date, array[count + 1].date) > 0)
            {
                temp = array[count];
                array[count] = array[count + 1];
                array[count + 1] = temp;
                swap = true;
            }
        }
    } while (swap);

}

This code produces this error:

error C2664: 'void bubbleSort(checkType,const int)' : cannot convert argument 1 from 'checkType [5]' to 'checkType'

So then I tried to change the function call from bubbleSort(checkArray, NUM); to bubbleSort(checkArray[NUM], NUM);

This code produces these errors:

error LNK2019: unresolved external symbol "void __cdecl bubbleSort(struct checkType,int)" (?bubbleSort@@YAXUcheckType@@H@Z) referenced in function _main

error LNK1120: 1 unresolved externals

Could someone please explain what I am doing wrong?

1
  • Just do MY_STRUCT_TYPE **array Commented Feb 24, 2015 at 1:55

1 Answer 1

7

Forward declaration:

void bubbleSort(checkType, const int);

Definition:

void bubbleSort(checkType array[], const int SIZE)

Those are not the same. The forward declaration should be:

void bubbleSort(checkType[], const int);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.