标题:关于输入档案程序的错误
只看楼主
hopepark
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2008-3-23
结帖率:100%
 问题点数:0 回复次数:3 
关于输入档案程序的错误
我用C++软件的F4检查功能,第一下是说我switch(num)里的一个括号有问题,但是我看了没问题啊,也没找出错的,请大家帮我找找错,谢谢大家,请问,如果我要在后面添加一个搜索功能,应该怎么写呢?
#include <stdio.h>
#include <stdlib.h>

struct directory{
    char name[20];
    char address[30];
    char telNum[9];
    struct directory* next;
    };

struct directory* head=NULL;
struct directory* tail=NULL;
struct directory* i=NULL;

void insert(void);
void del(void);
void print(void);

void main(void)
{
int num;
while(1){     
    printf("**menu**\n");
    printf("1.input\n");
    printf("2.delete\n");
    printf("3.print\n");
    printf("4.exit\n");
    printf("\n select number:");

    scanf("%d",&num);

    switch(num){
        case 1:
            insert();
            break;
        case 2:
            del();
            break;
        case 3:
            print();
            break;
        case 4:
            exit(1);
            break;
        default:
            printf("number select error.\n");
            break;
        }
    }
}

void insert(void)
{
    char iname[20];
    char iaddress[30];
    char iphone[9];
    
    printf ("name:");
    scanf ("%s",iname);    
    printf ("address:");
    scanf ("%s",iaddress);
    printf ("phone:");
    scanf ("%s",iphone);
    i = (struct directory*) malloc ( sizeof ( struct directory ));
    if ( head==NULL ){
            head=i;
            }

    else{
        tail->next=i;
        }

    strcpy (i->name,iname);
    strcpy (i->address,iaddress);
    strcpy (i->telNum,iphone);
    i->next=NULL;
    tail=i;
}

void del(void)
{
char iname[20];
struct directory* tempnode;
struct directory* afternode;
printf("deletename:");
scanf("%s",iname);
afternode=head;
    while (afternode!=NULL){
        if ( !strcmp (afternode->name,iname)){
            if (afternode==head){
                head=afternode->next;
                free( afternode);
                return;
            }
            else{
                tempnode->next=afternode->next;
                free (afternode);
                return;
            }
        }
    tempnode=afternode;
    afternode=afternode->next;
    }
printf("%s is Not exist directory in space\n",iname);
}

void print(void)
{
    struct directory* temptail;
    if(head==NULL)
        printf("Not exist directory in space.\n");
    else{
        temptail=head;
        printf("name\t address\t phone\n");
        while(temptail!=NULL){
        printf("-----------------------------\n name:%s\t address:%s\t phone:%s\n-----------------------------\n",temptail->name,temptail->address,temptail->telNum);
        temptail=temptail->next;
    }
}
}

[[it] 本帖最后由 hopepark 于 2008-11-4 14:19 编辑 [/it]]
搜索更多相关主题的帖子: 档案 输入 
2008-11-03 22:29
hopepark
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2008-3-23
得分:0 
谁可以帮下忙啊?谢谢了
2008-11-04 12:03
hopepark
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2008-3-23
得分:0 
谁可以帮下忙啊?谢谢了
2008-11-04 14:52
hopepark
Rank: 1
等 级:新手上路
帖 子:55
专家分:0
注 册:2008-3-23
得分:0 
难道没人帮忙了吗?
2008-11-04 20:19



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




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

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