Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

I have fixed the previous error I had. But I have other errors in my code, I tried but it's not working.

+4 votes
asked Aug 2, 2021 by npatel300 (1,440 points)
/*
 *
 *  srt.h file
 *
 */
#ifndef SRT_H
#define SRT_H
#include <string.h>
#include "srt.h"

#define MAX_BUF 256

#define swap(qx,qy,sz)                                              
do {                                                                
    char buf[MAX_BUF];                                              
    char *q1 = qx;                                                  
    char *q2 = qy;                                                  
    for (size_t m, ms = sz; ms > 0; ms -= m, q1 += m, q2 += m) {    
        m = ms < sizeof(buf) ? ms : sizeof(buf);                    
        memcpy(buf, q1, m);                                         
        memcpy(q1, q2, m);                                          
        memcpy(q2, buf, m);                                         
    }                                                               
} while (0)

int size_t = 1000000;
int arr[1000000];
void srtheap(void *, size_t, size_t, int (*)(const void *, const void *)){
    for(int i = nelem/2-1; i>=0; i--)
    srtheap(a, nelem, sizeof(TYPE), compare);

    for(int i = nelem - 1; i>=0; i--){
        swap(&arr[0], &arr[i], &nelem);
        srtheap(a, nelem, sizeof(TYPE), compare);
    }
    
    int largest = i;
    int left = 2 * i + 1;
    int right = 2 * i + 2;
    if(left < nelem &&arr[left] > arr[largest])
    largest = left;
    if(right < nelem &&arr[right] > arr[largest])
    largest = right;
    if(largest!= i){
        swap(&arr[i], &arr[largest], &nelem)
        heap(arr[i], nelem, largest);
    }   
}

#endif /* SRT_H */

1 Answer

0 votes
answered Aug 2, 2021 by Peter Minarik (86,040 points)
edited Aug 2, 2021 by Peter Minarik

Can you save your project in OnlineGDB, then click on the share button and share the link of your project?

This way one can fork from your project, creating a copy of it, and see what's going on really.

Also, as I mentioned before in http://question.onlinegdb.com/10544/fatal-error-such-file-directory-%23include-srt-should-resolve, your code is incomplete.

Did someone give it to you? You can also consult them why it doesn't work. What the owner of the code had in mind for those functions, etc.

Update

I looked at the code shared above. I have regretted it. :(

I'm fairly sure this is some copy-paste code without understanding of what it is doing.

Just some highlights of some serious mistakes:

  • redefining the type size_t to a variable name.
  • function declaration with argument types only (this is allowed), but then trying to reference the arguments by names
  • TYPE is not defined.
  • you're including the very same file (srt.h). Why would a header file need to include itself?
commented Aug 3, 2021 by npatel300 (1,440 points)
yes, the define swap portion is what our professor gave us. I have to include the preprocessor command include# "srt.h" in my srtheap.c file. Basically, I have to sort 1 million elements using heap sort. I need help. Thank you.
commented Aug 3, 2021 by Peter Minarik (86,040 points)
Can you save your project in OnlineGDB, then click on the share button and share the link of your project?

This way one can fork from your project, creating a copy of it, and see what's going on really.
commented Aug 3, 2021 by npatel300 (1,440 points)
Okay, here is a copy of my code. Please tell me what's wrong.
https://onlinegdb.com/Imh7okSIY
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...