0

I have few error commented after this text, i don't get what the compiler is trying to say me, the last function is in to do list i hope that's not the problem, the problem is i want to ask the user for 2 chars after that its send to a function who will compare the strings as a password and a login if the strings are the same, the program continues.

\\initializing argument 1 of int consultar(char, char)\\

\\invalid conversion from char*' to `char' \\

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

void introducir_datos (struct agenda cliente[30]);
void mostrar_datos(struct agenda cliente[30]);
char consultar(char login,char password);


struct agenda{
    char nombre[10];
    char apellido[10];
    int  edad;
    char direccion[20];
    int  codigo_postal;
};


int main(void)
{
    struct agenda cliente[30];  
    int menu;
    char con[3],login[8], password[8];
    puts("\n=== Hola bienvenido a nuestra agenda en C ===\n");

    puts("Login:");
    gets(login);
    puts("Password:");
    gets(password);
    **consultar(login, password);**
    while ( menu != 3){
        puts("\nQue quieres hacer?\n");
        puts("[1]Insertar datos\n[2]Mostrar datos\n[3]Salir del programa\n");
        scanf("%d", &menu);
        switch(menu){
            case 1:         
                introducir_datos(cliente);
                break;

            case 2:         
                mostrar_datos(cliente);
                break;

            default:
                system("cls");
                puts("~~~ Opcion incorrecta ~~~");

       }
    }
}

void introducir_datos (struct agenda cliente[30]){

    int x = 0;

    puts("\n=== Bienvenido a la introduccion de datos ===\n");
    fflush(stdin);
    system("pause");
    system("cls");
    puts("\nDime el nombre:\n");
    fflush(stdin);
    gets(cliente[x].nombre);
    puts("\nDime el apellido:\n");
    fflush(stdin);
    gets(cliente[x].apellido);
    puts("\nDime la edad:\n");
    fflush(stdin);
    scanf("%d",&cliente[x].edad);
    puts("\nDime la direccion:\n");
    fflush(stdin);
    gets(cliente[x].direccion);
    puts("\nDime el codigo postal:\n");
    fflush(stdin);
    scanf("%d",&cliente[x].codigo_postal);
    x++;    
}  


void mostrar_datos(struct agenda cliente[30]){

    for(int i=0;i<20;i++){     
        int x = 0;

        printf("El nombre: %s \nEl apellido: %s\nEl edad: %d\nEl direccion: %s\nEl codigo postal: %d\n", cliente[x].nombre,cliente[x].apellido,cliente[x].edad,cliente[x].direccion,cliente[x].codigo_postal);


    }     
}

int consultar(char login, char password){
}
BenMorel
  • 34,448
  • 50
  • 182
  • 322
José Vieiros
  • 75
  • 1
  • 13

1 Answers1

3

You need to change the consultar function (definition and implementation):

int consultar(char login, char password)

to:

int consultar(char *login, char *password)

If you use (char login, char password), it's looking for a single character. Since, by calling it with consultar(login, password);, you're using pointers to char arrays (simplified explaination), you're getting the error.

EDIT As pointed out by user "Namfuak", you should decide whether the function returns a char or an int, and have both definition and implementation be consistent.

Community
  • 1
  • 1
AntonH
  • 6,359
  • 2
  • 30
  • 40
  • It's also advisable to never, ever, ever (could go on forever) use `gets`. – Fiddling Bits Jul 31 '14 at 21:34
  • 1
    @FiddlingBits True. That's even got its own SO thread; http://stackoverflow.com/questions/1694036/why-is-the-gets-function-dangerous-why-should-it-not-be-used – AntonH Jul 31 '14 at 21:36
  • 1
    He should also match the return type on the declaration and definition of `consultar`, in the declaration it's a `char` but in the definition it's an `int`. – IllusiveBrian Jul 31 '14 at 21:36
  • @Namfuak Well spotted. Edited my answer to include this (credited). – AntonH Jul 31 '14 at 21:39