gpt4 book ai didi

C 程序在函数中获取无效转换

转载 作者:太空宇宙 更新时间:2023-11-04 07:15:34 26 4
gpt4 key购买 nike

我在这篇文章后评论了一些错误,我不明白编译器想告诉我什么,最后一个函数在待办事项列表中我希望这不是问题,问题是我想问用户2 个字符之后,它发送到一个函数,该函数将比较字符串作为密码和登录名,如果字符串相同,程序继续。

\\正在初始化 int consultar(char, char) 的参数 1\\

\\从 char*' 到 `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){
}

最佳答案

您需要更改consultar 函数(定义和实现):

int consultar(char login, char password)

到:

int consultar(char *login, char *password)

如果您使用 (char login, char password),它会查找单个字符。因为,通过使用 consultar(login, password); 调用它,您正在使用指向 char 数组的指针(简化解释),您会收到错误。

编辑 正如用户“Namfuak”所指出的,您应该决定函数返回的是char还是int,并且定义和实现都保持一致。

关于C 程序在函数中获取无效转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25069272/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com