标题:写了一道通讯录的程序题,出现了一些错误,望大神们帮我改一下!小弟不胜感激 ...
取消只看楼主
yang158
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2019-3-12
结帖率:16.67%
 问题点数:0 回复次数:0 
写了一道通讯录的程序题,出现了一些错误,望大神们帮我改一下!小弟不胜感激!
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
#include<windows.h>
#include<conio.h>
#define MaxSize 50
typedef struct {
    char name[20];
    char tel[15];
} ElemType;
typedef struct {
    ElemType data[MaxSize];
    int length;
} SqList;
void lnitList(SqList *&L) {
    L=(SqList*)malloc(sizeof(SqList));
      L->length=0;
}
void DispList(SqList*L) {
    int i;
    printf(" NO           NAME              TEL     \n");
    for(i=0; i<L->length; i++) {
        printf(" %d       %s       %s",i+1,L->data[i].name,L->data[i].tel);
        printf("\n");
        //fflush(stdin);
    }
    printf("目前联系人总数: %d\n",L->length);
    printf("\n");
}
bool Listlnsert(SqList*&L,int i,ElemType e) {
    int j;
    if(e.name=="\0")return false;
    if(i<1||i>L->length+1)
        return false;
    i--;
    for(j=L->length;j>i; j--)
        L->data[j]=L->data[j-1];
    L->data[i]=e;
    L->length++;
    //printf("length=%d\n\n",L->length);
    return true;
}
bool ListDelete(SqList*&L,int i,ElemType &e) {
    int j;
    if(i<1 || i>L->length)
        return false;
    i--;
    e=L->data[i];
    for(j=i; j<L->length-1; j++);
    {
        L->data[j]=L->data[j+1];
    }
    L->length--;
    printf("length=%d\n\n",L->length);
    return true;
}
void menu1() {
    printf("   --------------\n");
    printf("    手机通讯录的应用(顺序表)\n");
    printf("    --------------\n");
    printf("            1.建立通讯录\n");
    printf("            2.增加联系人信息\n");
    printf("            3.显示联系人信息\n");
    printf("            4.删除联系人信息\n");
    printf("            5.查找联系人信息\n");
    printf("            5.已退出!!!\n");
    printf("   ------------------------\n\n");
}
int LocateElem(SqList*L,ElemType e) {
    int i=0;
    while(i<L->length && strcmp(L->data[i].name,e.name)!=0)
        i++;
    if(i>=L->length)
        return 0;
    else {
        puts(L->data[i].name);
        puts(L->data[i].tel);
        //printf("%s,%s\n",L->data[i].name,L->data[i].tel);
        return(i+1);
    }
}
void main() {
    SqList*L;
    int flag=1;
    int j;
    ElemType s[4]= {"陆 毅","13975053309","张珊珊","13975053389","邓 超","13989003389","张 本","1297809987"};
    ElemType e;
    menu1();
    printf("   (1)初始化顺序表L\n");
    lnitList(L);
    printf( "   (2)依次插入元素\n");
    for(int i=0; i<4; i++)
        Listlnsert(L,i+1,s[i]);
    DispList(L);
    while(flag==1) {
        printf("请选择: ");
        scanf("%d",&j);
        switch(j) {
            case 2:
                printf("请输入联系人姓名和电话号码: ");
                scanf("%s%s",e.name,e.tel);
                printf("请输入插入数据的位置: ");
                scanf("%d",&i);
                fflush(stdin);
                printf("\n");
                Listlnsert(L,i,e);
                break;
            case 3:
                DispList(L);
                break;
            case 4:
                printf("请输入删除数据的位置: ");
                scanf("%d",&i);
                ListDelete(L,i,e);
                break;
            case 5:
                printf("请输入查找的联系人姓名: ");
                scanf("%s",&e.name);
                LocateElem(L,e);
                break;
            case 6:
                flag=0;
                printf("\n      不再输入记录,退出!!\n\n");
                break;
        }
    }
}
搜索更多相关主题的帖子: data length int printf NAME 
2020-03-04 19:45



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




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

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