Home > Enterprise >  Passing variable from mulitple functions to another function in C
Passing variable from mulitple functions to another function in C

Time:10-07

Basically I need to pass the ret variable from the functions checkPOS, checkPOS1, checkPOS2 to the result() function, if the sum of the 3 ret variables equals to zero, user's access is granted, in case it is 1 , the access is denied. How can I pass the 3 variables to the result function?

 void checkPOS2(struct Node* n, int pos, int alg, int input) {
    
        int ret3;
    
        for (int i = 0; i < pos - 1; i  ) {
            n = n->next;
        }
    
        
    
        if (input == n->data[alg]) {
            printf("Numero certo (");
            printf("%d", n->data[0]);
            printf("%d", n->data[1]);
            printf("%d)", n->data[2]);
            ret3 = 0;
            return ret3;
        }
        else {
            printf("Numero errado (");
            printf("%d", n->data[0]);
            printf("%d", n->data[1]);
            printf("%d)", n->data[2]);
            ret3 = 1;
            return ret3;
        }
    
    
    }
    
    void result() {
      
        
        if ((ret3) == 0) { printf("Acesso Permitido!"); }
        else { printf("Acesso Negado!"); }
    
        printf("%d", ret3);
        
    
    }

CodePudding user response:

It needs to take parameter as well.

void result(int r) 
{
        if ((r) == 0) { printf("Acesso Permitido!"); }
        else { printf("Acesso Negado!"); }
    
        printf("%d", r);
}

and before you call it:

int res = checkPOSx(....);
result(res);

or

result(checkPOSx(....));
  • Related