Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Passing variable from mulitple functions to another function in C

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);
        
    
    }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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(....));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading