标题:为何最后在控制台无论输入几都会显示操作错误,把操作错误的代码删除后在输 ...
只看楼主
dhjxbxhdj
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2022-10-13
 问题点数:0 回复次数:1 
为何最后在控制台无论输入几都会显示操作错误,把操作错误的代码删除后在输入数字就会一直闪屏,刚开始学代码的大一新生,求解答,谢谢
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//using namespace std;

#define max 100//最大联系人数量

struct people//联系人结构体
{
    char name;//姓名

    char company;//工作单位

    char phone;//电话

    char e_mail;//邮箱
};

struct addressbook//通讯录结构体
{
    struct people arr[max];//联系人数组

    int size;//联系人数量
};

void menu()//菜单功能
{
    printf ( "*******************\n")  ;
    printf ( "=    1.增加联系人    =\n") ;
    printf ("=     2.删除联系人    =\n") ;
    printf ( "=    3.修改联系人    =\n");
    printf ( "=    4.查找联系人    =\n");
    printf ( "=    5.显示联系人    =\n");
    printf ( "=    6.退出通讯录    =\n");
    printf ( "####################" );

}

void addpeople(addressbook* wit)//增加联系人功能
{
    if (wit->size == max)//判断联系人数量
    {
        printf( "联系人已满,请删除一些后再来\n");
        return;
    }
    else
    {
        char NAME = '\0';
        printf( "请输入姓名\n");
        scanf_s("NAME");
        wit->arr[wit->size].name = NAME;

        char COMPANY = '\0';
        printf( "请输入工作单位\n");
        scanf_s(" COMPANY");
        wit->arr[wit->size].company = COMPANY;

        char PHONE = 0;
        printf( "请输入电话\n");
        scanf_s( "PHONE\n");
        wit->arr[wit->size].phone = PHONE;

        char E_MAIL = '\0';
        printf(" 请输入邮箱\n");
        scanf_s(" E_MAIL");
        wit->arr[wit->size].e_mail = E_MAIL;

    }
    wit->size++;
    printf( "添加成功\n");
    system ("pause");
}

void deletepeople(addressbook* wit, int a)//删除联系人功能
{
    for (int i = a; i < wit->size; i++)
    {
        wit->arr[i].name = wit->arr[i + 1].name;
        wit->arr[i].company = wit->arr[i + 1].company;
        wit->arr[i].phone = wit->arr[i + 1].phone;
        wit->arr[i].e_mail = wit->arr[i + 1].e_mail;
    }
   
}

void changepeople(addressbook* wit, int a)
{
    char NAME = '\0';
    printf( "请输入姓名\n");
    scanf_s(" NAME");
    wit->arr[a].name = NAME;

    char COMPANY = '\0';
    printf( "请输入工作单位\n");
    scanf_s(" COMPANY");
    wit->arr[a].company = COMPANY;

    char PHONE = '\0';
    printf( "请输入电话\n");
    scanf_s(" PHONE");
    wit->arr[a].phone = PHONE;

    char E_MAIL = '\0';
    printf( "请输入邮箱\n");
    scanf_s(" E_MAIL");
    wit->arr[a].e_mail = E_MAIL;

    printf("联系人已修改!\n");
}

int findpeople(addressbook* wit, char name)//查找联系人功能
{
    for (int i = 0; i < wit->size; i++)
    {
        if (name == wit->arr[i].name)
        {
            return i;
        }
    }
    return -1;
}

void showpeople(addressbook* wit)//显示联系人功能
{
    if (wit->size == 0)
    {
        printf( "目前通讯录为空\n");
    }
    else
    {
        for (int i = 0; i < wit->size; i++)
        {
            printf ( " 姓名: wit->arr[i].name\t" );
            printf(" 工作单位:  wit->arr[i].company \t");
            printf("电话:  wit->arr[i].phone \t");
            printf("邮箱:  wit->arr[i].e_mail \t");
            printf("\t");
        }
    }
    system("pause");
    return;
}

int main()
{

    struct addressbook wit;

    wit.size = 0;

    int choice = 0;

    while (true)
    {

        menu();

        scanf_s("choice");

        switch (choice)
        {
        case 1://增加
        {
            addpeople(&wit);
            break;
        }
        case 2://删除
        {
            if (wit.size == 0)
            {
                scanf_s("目前通讯录为空\n");
            }
            else
            {
                char name = '\0';
                printf("请输入您要删除的姓名:");
                scanf_s(" name");
                int a = findpeople(&wit, name);
                if (a > -1)
                {
                    deletepeople(&wit, a);
                }
                else
                {
                    printf( "查无此人\n");
                }
            }
            system("pause");
            break;
        }
        case 3://修改
        {
            if (wit.size == 0)
            {
                printf( "目前通讯录为空\n");
            }
            else
            {
                char name = '\0';
                printf( "请输入您要修改的姓名:");
                scanf_s("name");
                int a = findpeople(&wit, name);
                if (a > -1)
                {
                    changepeople(&wit, a);
                }
                else
                {
                    printf( "查无此人\n" );
                }
            }
            system("pause");
            break;
        }
        case 4://查找
        {
            if (wit.size == 0)
            {
                printf( "目前通讯录为空\n");
            }
            else
            {
                char Name = '\0';
                printf( "请输入您要查找的姓名:");
                scanf_s(" Name");
                int a = findpeople(&wit, Name);
                if (a > -1)
                {
                    printf( "姓名:wit.arr[a].name \t");
                    printf ("工作单位: wit.arr[a].company \t");
                    printf( "电话: wit.arr[a].phone \t");
                    printf( "邮箱: wit.arr[a].e_mail \t");
                    printf(" endl");
                }
                else
                {
                    printf( "查无此人\n");
                }
            }
            system("pause");
            break;
        }
        case 5://显示
        {
            showpeople(&wit);
            break;
        }
        case 6://退出
        {
            printf( "您已退出通讯录\n");
            system("pause");
            return 0;
            break;
        }
        default:
        {
            printf ( "操作错误\n" );
            system("pause");
            break;
        }
        }
        system("cls");
    }
}
搜索更多相关主题的帖子: 联系人 输入 name char printf 
2022-12-08 16:23
dhjxbxhdj
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2022-10-13
得分:0 
回复 楼主 dhjxbxhdj
解决了,被自己的错误蠢哭了
2022-12-08 16:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-510891-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.349292 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved