馒头小子啊 2023-02-11 15:45 采纳率: 37.5%
浏览 34
已结题

Del函数哪里有问题?

Del函数哪里有问题?

img


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define Max_Name 200
#define Max_Tel 20
#define NumberOfMem 10

void menu();
void Init();
void Add();
void Show();
void menu()
{
    printf("\t\t\t***************************************\t\t\n");
    printf("\t\t\t**************1.Add     2.Del**********\t\t\n");
    printf("\t\t\t***************************************\t\t\n");
    printf("\t\t\t***************3.Search   4Modify******\t\t\n");
    printf("\t\t\t***************************************\t\t\n");
    printf("\t\t\t***************5.Show      0.Exit******\t\t\n");
}
struct PeoIfor
{
    char name[Max_Name];
    char tel[Max_Tel];
    char sex[3];
};

struct Contact
{
    struct PeoIfor data[NumberOfMem];
    int size;
};
void Init(struct Contact* ps)
{
    memset(ps->data, 0, sizeof(ps->data));
    ps->size = 0;
}
void Add(struct Contact* ps)
{

    if (ps->size == NumberOfMem)
    {
        printf("The contact is full,you can't add the contact\n");
    }
    else
    {
        printf("Please type the contact's name:\n");
        scanf("%s", ps->data[ps->size].name);
        printf("Please tpye the contact's telephone number\n");
        scanf("%s", ps->data[ps->size].tel);
        printf("What's the sex of the contact you just added?\n");
        scanf("%s", ps->data[ps->size].sex);
        ps->size++;
        printf("**************Sucessfully Added!*****************\n");
        printf("There's %d people in your contactn\n", ps->size);

    }
}
            
void Show(const struct Contact *ps)
{
    printf("%s\t%-12s\t%-12s\t%-12s\t\t\n", "|Num|","|Name|", "|Sex|", "|Tele|");
    if (ps->size == 0)
    {
        printf("The contact is void!\n");
    }
    else
    {
        for (int i = 0; i < ps->size; i++)
        {
            printf("%-d\t%-12s\t%-12s\t%-12s\t\t\n",i,
                ps->data[i].name,
                ps->data[i].sex,
                ps->data[i].tel);
        }
    }
    
}
void Del( struct Contact* ps)
{
    int i = 0;
    void Show(const struct Contact* ps);
    printf("Please Input the name or num you want to delete\n");
    char input[Max_Name];
    scanf("%s", &input);
    for (i = 0; i < ps->size; i++)
    {
        if((strcmp(ps->data->name,input[Max_Name]))==0)
        {
            break;
        }
        else if (strcmp(ps->size, input[Max_Name]))
        {
            break;
        }
        else if (i == ps->size)
        {
            printf("We can't find the one you type in\n");
        }
    }
    for (int j = i; j < ps->size; j++)
    {
        ps->data[j] = ps->data[j + 1];
        break;
    }
    printf("Successfully Deleted!!\n");
}
#include"contant.h"

int main()
{
    struct Contact con;
    Init(&con);
    printf("\t\t\tSuccessfully Initialized!!\t\t\n");
    int sel;
    do
    {

        menu();

        scanf("%d", &sel);
        switch (sel)
        {
        case 1:
            Add(&con);
            break;
        case 2:
            Del(&con);
            break;
        case 3:
            break;
        case 4:
            break;
        case 5:
            Show(&con);
            break;
        case 0:
            exit(0);
        default:
            
            printf("Wrong input Please try again!\n");
            break;

        }


    } while (sel);
    return 0;
}

  • 写回答

3条回答 默认 最新

  • 元气少女缘结神 2023-02-11 16:01
    关注

    不要把函数声明void Show(const struct Contact* ps);放在函数Del里。删掉。这句scanf("%s", &input);原来input就是数组的地址了,不要再取 &

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 2月19日
  • 已采纳回答 2月11日
  • 创建了问题 2月11日

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法