run out of here 2022-04-16 21:47 采纳率: 100%
浏览 14
已结题

代码如下:将信息录入后再次回到switch 语句,一直运行default,没法选择其他的选项,不知道是什么问题


#include "stdio.h"
#include "stdlib.h"
#include "assert.h"


typedef struct student {
    char Name[20];
    int StuID;
    int Grade;
    
}stu;

//创建表
struct Node {
    struct student data;
    struct Node* next;
};

//创建表头
struct Node* createList() {
    struct Node* headNode = (struct Node*)malloc(sizeof(struct Node));
    assert(headNode);
    headNode->next = NULL;
    return headNode;
}

//创建结点
struct Node* createNode(struct student data) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    assert(newNode);
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}

//指定节点删除
void deleteAppointNodeByID(struct Node* headNode,int posID) {
    struct Node* posNode = headNode->next;
    struct Node* posFrontNode = headNode;
    if (posNode == NULL) {
        printf("数据为空,无法删除!\n");
        return;
    }
    while (posNode->data.StuID = posID) {
        posFrontNode = posNode;
        posNode = posFrontNode->next;
        if (posNode == NULL) {
            printf("未找到指定位置,无法删除!\n");
            return;
        }
    }
    posFrontNode->next = posNode->next;
    free(posNode);

}

//查找功能
struct Node* searchInfoByData(struct Node* headNode, int posData) {
    struct Node* posNode = headNode;
    while (posNode!=NULL) {
        if (posNode->data.StuID == posData)
            return posNode;
        posNode = posNode->next;
    }
    printf("无法找到结点\n");
    return NULL;
}


//插入结点
void insertNodeByHead(struct Node* headNode, struct student data) {
    struct Node* newNode = createNode(data);
    newNode->next = headNode->next;
    headNode->next = newNode;
}

//打印链表
void printList(struct Node* headNode) {
    struct Node* pMove = headNode->next;
    printf("Name\tStuID\tGrade");
    while (pMove) {
        printf("%s\t%d\t%d",pMove->data.Name,pMove->data.StuID,pMove->data.Grade);
        pMove = pMove->next;
    }
    printf("\n");
}

//建表


//按键交互
void keyDown() {
    struct Node* list = createList();
    struct student data;
    printf("请输入:(0`4)\n");
    switch (getchar()) {
    case '0':
        printf("正常退出!\n");
        system("pause");
        exit(0);
        break;
    case '1':
        printf("录入信息:\n");
        //插入链表
        printf("请输入学生姓名,学号,成绩\n");
        fflush(stdin);
        scanf_s("%s%d%d",data.Name,4,&data.StuID,&data.Grade);
        insertNodeByHead(list,data);
        break;
    case '2':
        printf("浏览信息:\n");
        printList(list);
        break;
    case '3':
        printf("删除信息:\n");
        break;
    case '4':

        printf("查找信息:\n");
        break;
    default:
        printf("输入错误,请重新输入!\n");
        break;
    }
}

//菜单
void menu() {
    printf("----------------------------\n");
    printf("学生信息管理系统\n");
    printf("1.录入信息\n");
    printf("2.浏览信息\n");
    printf("3.删除信息\n");
    printf("4.查找信息\n");
    printf("0.退出系统\n");
    printf("----------------------------\n");
}



int main() {


    while (1) {
        menu();
        keyDown();
        system("pause");
        system("cls");
    }
    system("pause");
    return 0;
}


img

  • 写回答

1条回答 默认 最新

  • 不会长胖的斜杠 后端领域新星创作者 2022-04-16 22:04
    关注

    case 0
    case 1
    不要用引号包括
    望采纳

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 9月12日
  • 已采纳回答 9月4日
  • 创建了问题 4月16日

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line