Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiler Error "void value not ignored as it ought to be" in C programming [duplicate]

I got that error which cant figure out. I look over related questions but I dont give a meaning someone show me which part do I need to fix?

[Error] void value not ignored as it ought to be

My codes

void getEdge(char str[],char *token){
    *token = strtok(str, "_,");
    while (token != NULL )
    {
      //  printf("%s\n", token);
        token = strtok(NULL, "_,");
    }

}

void getEdge(char str[],char *token);

int main () {
    char arr[] = "A_B_10,A_F_6,B_C_6,C_B_10,D_A_3";
    char *toke;
    char result;
    result = getEdge(arr,toke);
    printf("%s\n",result);

}
like image 813
necromencer Avatar asked Dec 18 '22 22:12

necromencer


1 Answers

Check this line

 result = getEdge(arr,toke);

you're trying to capture the return value of a function for which the return type is void.

Remember, void is an incomplete type, and it's not compatible with any other type (in this case, LHS is char), hence the compiler rightly complains.

That said,

*token = strtok(str, "_,");

inside the function also does not look very correct. Check the types there.

like image 66
Sourav Ghosh Avatar answered Dec 29 '22 10:12

Sourav Ghosh