简体   繁体   中英

Argument type 'void' is incomplete

I'm trying to code this relatively simple code in which I want to be able to change the value of set_current. The error message: "Argument type 'void' is incomplete" keeps showing up and I'm not sure why.

I am not an experienced coder but I have to solve this problem for work. I really hope you can help me.

void setCurrent(float set_current);

int main () { 
    printf("%i", setCurrent(0));
    printf("/n/r");
}

void setCurrent(float set_current){
    float v_set_cur = 1.25 + (ILIM_K_USE*set_current);

"Argument type 'void' is incomplete" shows up on the printf line. When I remove the 0 then it works but I want to be able to change that number. What am I missing here?

You've declared setCurrent as returning void (ie, nothing), yet in printf("%i", setCurrent(0)); you're expecting it to return an int . One of those things needs to be changed.

What am I missing here?

You are missing that the function setCurrent needs to return a value that you can print. In other words - the function definition shall not be void .

My guess is that you want:

float setCurrent(float set_current);  // Notice float instead of void

int main () { 
    printf("%f", setCurrent(0));      // Notice %f instead of %i
    printf("/n/r");
}

float setCurrent(float set_current){                    // Notice float instead of void
    float v_set_cur = 1.25 + (ILIM_K_USE*set_current);  // Calculate value
    return v_set_cur ;                                  // Return the value
}

When you call setCurrent, nothing is being returned. A void function inherently does not return a value. Based on your printf statement, you are expecting an integer from calling setCurrent. It appears you want to return a float because v_set_curr is a float.

float setCurrent(float set_current);

int main () { 
    printf("%f", setCurrent(0));
    printf("/n/r");
}

float setCurrent(float set_current){
    float v_set_cur = 1.25 + (ILIM_K_USE*set_current);
    return v_set_cur;
}

void return type does not return any value; so print operation you should do inside setCurrent function.
Try this code

void setCurrent(float set_current);

int main () { 
    setCurrent(0);
    printf("/n/r");
}

void setCurrent(float set_current){
    float v_set_cur = 1.25 + (ILIM_K_USE*set_current);
    printf("%.2f", v_set_cur);
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM