C语言链表账号密码系统

C语言zuo业,编了一个链表,但是运行起来报错,请大家指点

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student {
    char* account;
    char* password;
};
struct Node {
    struct Student data;
    struct Node* next;
};

struct Node* createList()
{
    struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));
    headNode->next = NULL;
    return headNode;
}

struct Node* createNode(struct Student data)
{
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}

void insertNodeByHead(struct Node* headNode, struct Student data)
{
    struct Node* posNode = headNode->next;
    struct Node* posNodeFront = headNode;
        while (strcmp(posNode->data.account, data.account) != 0)
        {
            posNodeFront = posNode;
            posNode = posNodeFront->next;
            if (strcmp(posNode->data.account, data.account) == 0)
            {
                printf("已存在,无法注册\n");
                return;
            }
            if (posNode == NULL)
                break;
        }
    struct Node* newNode = createNode(data);
    newNode->next = headNode->next;
    headNode->next = newNode;
    printf("已成功注册!\n");
}

void changeNode(struct Node* headNode, struct Student data) {
    struct Node* posNode = headNode->next;
    struct Node* posNodeFront = headNode;
        while (strcmp(posNode->data.account, data.account) != 0)
        {
            posNodeFront = posNode;
            posNode = posNodeFront->next;
        }
        strcpy(posNode->data.password, data.password);
}

void deleteNodeByAppoint(struct Node* headNode, char* posData)
{
    struct Node* posNode = headNode->next;
    struct Node* posNodeFront = headNode;
    if (posNode == NULL)
    {
        printf("没有找到\n");
        return;
    }
    else
    {
        while (strcmp(posNode->data.account ,posData)!=0)
        {
            posNodeFront = posNode;
            posNode = posNodeFront->next;
            if (posNode == NULL)
            {
                printf("没有找到\n");
                return;
            }
        }
        posNodeFront->next = posNode->next;
        free(posNode);
        printf("已成功删除!\n");
    }
}

int main() {
    int n=0;
    struct Node* list = createList();
out1: {
    printf("请选择操作:\n1.注册账号\n2.登录账号\n3.删除账号\n4.修改密码\n请输入数字选项:");
    scanf("%d", n);
    switch (n) {
    case 1: {
        printf("请输入用户名:");
        char account[] = {0};
        scanf("%s", account);
        printf("请输入密码:");
        char password[] = {0};
        scanf("%s", password);
        struct Student data = { 0,0 };
        strcpy(data.account, account);
        strcpy(data.password, password);
        insertNodeByHead(list, data);
        goto out1;
    }
    case 2: {
        printf("请输入用户名:");
        char account[] = {0};
        scanf("%s", account);
        struct Node* posNode = list->next;
        struct Node* posNodeFront = list;
        if (posNode == NULL)
        {
            printf("没有找到\n");
            goto out1;
        }
        else
        {
            while (strcmp(posNode->data.account, account) != 0)
            {
                posNodeFront = posNode;
                posNode = posNodeFront->next;
                if (posNode == NULL)
                {
                    printf("没有找到\n");
                    goto out1;
                }
            }
            printf("请输入密码:");
            char password[] = {0};
            scanf("%s", password);
            if (strcmp(posNode->data.password, password) != 0)
            {
                printf("密码错误!\n");
                goto out1;
            }
            else
            goto out1;
        }
    }
    case 3: {
        printf("请输入要删除的用户名:");
        char account[] = {0};
        scanf("%s", account);
        deleteNodeByAppoint(list, account);
        goto out1;
    }
    case 4: {
        printf("请输入要修改的用户名:");
        char account[] = {0};
        scanf("%s", account);
        struct Node* posNode = list->next;
        struct Node* posNodeFront = list;
        if (posNode == NULL)
        {
            printf("没有找到\n");
            goto out1;
        }
        else
        {
            while (strcmp(posNode->data.account, account) != 0)
            {
                posNodeFront = posNode;
                posNode = posNodeFront->next;
                if (posNode == NULL)
                {
                    printf("没有找到\n");
                    goto out1;
                }
            }
            printf("请输入新密码:");
            char password[] = {0};
            scanf("%s", password);
            struct Student data = { 0,0 };
            strcpy(data.account, account);
            strcpy(data.password, password);
            changeNode(list, data);
            printf("修改成功!\n");
            goto out1;
        }
    }
  }
 }
    return 0;
}
struct Student {
    char* account;
    char* password;
};
//修改
struct Student {
    char account[20];
    char password[20];
};

scanf("%d", n);
//修改
scanf("%d", &n);

 struct Node* posNode = headNode->next;//不明白这是要干嘛,但显然是错误的,head->next一开始为NULL
  • 以下回答由chatgpt基于相关博客总结生成:

    抱歉,由于问题描述不够详细且缺乏错误提示信息,我无法确定链表账号密码系统的具体错误。请提供更多信息,比如错误提示信息和出错代码段等,以便更好地解决问题。