Heapsort in C, index 0 issue.
for a project for school I have decided to solve a problem by coding a HeapSort but I have an issue. ("vector" is the vector to sort and "n" is the number of elements in "vector")

Here is my code :

    void fixHeap(int position,int length)
    {
        int next=2*position;
        int temp;
    
        while (next<=length)
        {
            if (next<length && vector[next]<vector[next+1])
            {
                next++;
            }
            if (vector[position]<vector[next])
            {
                temp=vector[position];
                vector[position]=vector[next];
                vector[next]=temp;
                position=next;
                next=2*position;
            }
            else
            {
                return;
            }
        }
    }
    
    void heapSort()
    {
        int counter;
        int temp;
    
        for(counter=(n-1)/2;counter==0;counter--)
        {
            fixHeap(counter,n-1);
        }
        for(counter=n-1;counter>0;counter--)
        {
            temp=vector[counter]; 
            vector[counter]=vector[0];
            vector[0]=temp;
            fixHeap(0,counter-1);
        }
        display();
    }

When I'm doing fixHeap(0,n-1) I'm putting next to 0 and then position is also at 0 so I'm not really doing the Heap right. Could someone help me fixing it?

Also are there other mistakes that you spotted that I may have overlooked? 
Heapsort in C, index 0 issue.
===

for a project for school I have decided to solve a problem by coding a HeapSort but I have an issue. ("vector" is the vector to sort and "n" is the number of elements in "vector")

Here is my code :

    void fixHeap(int position,int length)
    {
        int next=2*position;
        int temp;
    
        while (next<=length)
        {
            if (next<length && vector[next]<vector[next+1])
            {
                next++;
            }
            if (vector[position]<vector[next])
            {
                temp=vector[position];
                vector[position]=vector[next];
                vector[next]=temp;
                position=next;
                next=2*position;
            }
            else
            {
                return;
            }
        }
    }
    
    void heapSort()
    {
        int counter;
        int temp;
    
        for(counter=(n-1)/2;counter==0;counter--)
        {
            fixHeap(counter,n-1);
        }
        for(counter=n-1;counter>0;counter--)
        {
            temp=vector[counter]; 
            vector[counter]=vector[0];
            vector[0]=temp;
            fixHeap(0,counter-1);
        }
        display();
    }

When I'm doing fixHeap(0,n-1) I'm putting next to 0 and then position is also at 0 so I'm not really doing the Heap right. Could someone help me fixing it?

Also are there other mistakes that you spotted that I may have overlooked? 