Del函数哪里有问题?
#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;
}