1
I am trying to adapt a C++ function into pure C. I have changed the variable names and structs because it’s beside the point.
typedef struct struct1 {
    int a;
    int b;
    int c;
    string d;
} STRUCT1;
typedef struct struct2 {
    int aa;
    int bb;
    int cc;
    clock_t time;
} STRUCT2;
vector<STRUCT2> createVector(STRUCT1 str1) 
{
    vector<STRUCT2> vec;
    int var = str1.c, count = 0;
    for (int i = 0; i < str1.b; i++) {
        usleep(1);
        STRUCT2 aux;
        aux.aa = 0;
        aux.bb = count;
        aux.cc = 0;
        aux.time = clock();//start times
        vec.push_back(aux);
        if (--var == 0) {
            var = str1.c;
            count++;
        }
    }
return vec;
}
My doubts are:
- vector<STRUCT2> createVector(STRUCT1 str1)
- vector<STRUCT2> vec;
- vec.push_back(aux);
How I would pass these 3 lines of code to pure C in the above code?
Emoon, I used this format and it worked... (in parts) I’m having trouble printing this vector returned... example:
– Oberdan Santos
@Oberdansantos I’m sorry to reject your edition, but it significantly altered the answer, even if it is only one
*Plus. If this was a silly little mistake about something Emoon forgot, then everything would be fine. But it turns out, at least in my opinion, the code should not compile with the*and the way that Emoon left it should be right. Cases like this would be best solved through conversations in comments.– Victor Stafusa
@Victorstafusa Quiet, got it.
– Oberdan Santos