How to pass the registration code as a function parameter?

Asked

Viewed 93 times

0

I have to sort down the salaries of employees of a company. Entree: Tuition, salary, if you wish to continue Exit: Wages in descending order. The error that is appearing is the following:

[Warning] Passing argument 1 of 'le_valida_matricula' makes integer from Pointer without a cast

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* 
Lucas Correia Barros Lauriano
Síntese
Objetivo: Ordenar de forma decrescente os salários dos funcionarios de uma empresa
Entrada: Matrícula, salário, se deseja continuar
Saída: Salários em ordem decrescente

*/


char valida_caracter(char opc1, char opc2, char titulo[]);
int le_valida_matricula(int mat, char titulo[]);

int main() {

    char matricula_func[0];
    float salario_func[0];
    char opc;



    do{


        matricula_func = le_valida_matricula(matricula_func, "Informe a matricula do funcionario: ");
        fflush(stdin);
        printf("Informe o salario do funcionario:");
        scanf("%d", &salario_func);



        opc = valida_caracter('s', 'n', "Pressione S para continuar");

        system("cls");
    }while(opc == 's');

    return 0;
}

char valida_caracter(char opc1, char opc2, char titulo[]){
    char opc;
    do{ 
    printf(titulo);
    opc = getch();
    fflush(stdin);
    opc = tolower(opc);

    if(opc !='s' && opc!= 'n'){
        system("cls");
        printf("Opcao invalida! Digite %c ou %c que sao opcoes valida\n", opc1, opc2);
    }
    }while(opc !='s' && opc!= 'n');

    return opc;
}

int le_valida_matricula(int mat, char titulo[]){

    int aux;

    do{
        printf(titulo);
        scanf("%d", &aux);

        if(aux == '\0')
            {
                printf("Deve ser diferente de vazio!");
            }

    }while(aux == '\0');

    return aux; 
}

1 answer

0


First you were trying to pass a variable as a parameter without having given a value to it, and you were making it itself receive what the function returned, here: matricula_func = le_valida_matricula(matricula_func, "Informe a matricula do funcionario: ");

Second, you were not defining which vector position you wanted to assign a value to. I took the liberty of creating a count variable i. And I put the function call le_valida_matricula() without dependence on parameters, I did what you were doing but within the function itself.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* 
Lucas Correia Barros Lauriano
Síntese
Objetivo: Ordenar de forma decrescente os salários dos funcionarios de uma empresa
Entrada: Matrícula, salário, se deseja continuar
Saída: Salários em ordem decrescente

*/


char valida_caracter(char opc1, char opc2, char titulo[]){
    char opc;
    do{ 
    printf(titulo);
    opc = getch();
    fflush(stdin);
    opc = tolower(opc);

    if(opc !='s' && opc!= 'n'){
        system("cls");
        printf("Opcao invalida! Digite %c ou %c que sao opcoes valida\n", opc1, opc2);
    }
    }while(opc !='s' && opc!= 'n');

    return opc;
}

int le_valida_matricula(){

    int aux;

    do{
        printf("Qual a matricula do funcionario?");
        scanf("%d", &aux);

        if(aux == '\0')
            {
                printf("Deve ser diferente de vazio!");
            }

    }while(aux == '\0');

    return aux; 
}

int main() {

    char matricula_func[0];
    float salario_func[0];
    char opc;
    int i=0;



    do{


        matricula_func[i] = le_valida_matricula();
        fflush(stdin);
        printf("Informe o salario do funcionario:");
        scanf("%d", &salario_func);
        i++;


        opc = valida_caracter('s', 'n', "Pressione S para continuar");

        system("cls");
    }while(opc == 's');

    return 0;
}
  • Thanks, Eduardo! I’ll take a look at the code later. And try to understand what you did too. I still have to do a lot of things, but if I understand this first exercise correctly, it’s already halfway.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.