首页 > 解决方案 > 总线错误:尝试在方法之间传递字符时返回 10

问题描述

嗨,我是 c 语言的新手,还没有完全理解指针。我正在为我的程序编写一个简单的用户名/密码认证过程,它目前看起来像这样:

void authenticate_process(int cli_sockfd){

    /* Authentication Process */
    write(cli_sockfd, "USN", 3);
    char *username;
    username = recv_msg(cli_sockfd);
    printf("[DEBUG] Client username is %s.\n", username);

    write(cli_sockfd, "PSW", 3);
    char *password;
    password = recv_msg(cli_sockfd);
    printf("[DEBUG] Client Password is %s.\n", password);

//From Here the program breaks 
    bool approval = authenticate_login(username, password);
    printf("%c", approval);
}


bool authenticate_login(char *username, char *password)
{
    printf("Made it here");

    FILE *file;
    char *file_username;
    char *file_password;
    bool match;
    printf("%s", username);
    printf("%s", password);
// BLAH BLAH BLAH MORE CODE IN THIS SECTION 

    return match;
}

我可以在 authenticate_process 方法中获取并打印出客户端的用户名和密码,但是一旦我到达线路,bool approval = authenticate_login(username, password);Bus Error: 10相信这与我如何传递字符有关,但我可能是错的。有人可以解释一下并告诉我如何解决我的问题吗?

标签: cpointerschar

解决方案


推荐阅读