| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 355 人关注过本帖
标题:一个纠结的c语言问题(双向链表练习)
只看楼主 加入收藏
ygl6566
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-11-15
收藏
 问题点数:0 回复次数:0 
一个纠结的c语言问题(双向链表练习)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<fstream.h>
#include<iostream.h>
struct address
{
    char name[9];
    char street[40];
    char city[9];
    char province[9];
    char zip[7];
    struct address *prior;
    struct address *next;
}list_entry;
struct address *start;
struct address *last;
void enter(),display(),search(),save(),load();
main()
{
    char s[80],choice;
    struct address *info;
    start=last=NULL;
    for(;;)
    {
        switch(menue_select())
        {
         case 1:enter();break;
         case 2:delete();break;
         case 3:list();break;
         case 4:search();break;
         case 5:save();break;
         case 6:load();break;
         case 7:exit(0);
        }
    }
}

menue_select()
{
    char *s[80];
    int c;
    printf("\t 请选择功能:\n\n");
    printf("\t 1.输入通讯处:\n");
    printf("\t 2.删除通讯处:\n");
    printf("\t 3.列表显示:\n" );
    printf("\t 4.查找:\n");
    printf("\t 5.将文件存盘:\n");
    printf("\t 6.将文件从盘中装入:\n");
    printf("\t 7.退出:\n");
    do{
         printf("\n\t请按数字键选择:");
         gets(s);
         c=atoi(s);
        }while(c<0||c>7);
    return(c);
}
void enter()
{
    struct address *info,dls_store();
    for(;;)
    {
        info=(struct address *)malloc(sizeof(list_entry));
        if(!info)
        {
            printf("\t内存已用完!\n");
            return;
        }
        inputs("\t 请输入姓名:",info->name,8);
        if(!*info->name) break;
        inputs("\t 请输入街名:",info->street,39);
        inputs("\t 请输入市名:",info->city,8);
        inputs("请输入省名:",info->province,8);
        inputs("请输入邮编:",info->zip,7);
        *start=dls_store(info, start);
    }
}
inputs(prompt,s,count)
char *prompt,*s;
int count;
{
    char p[255];
    do{
        printf(prompt);
        gets(p);
        if(strlen(p)>count)
            printf("\t 太长了!");
        }while(strlen(p)>count);
    strcpy(s,p);
}
struct address *dls_store(i,top)
struct address *i;
struct address *top;
{
    struct address *old,*p;
    if(last==NULL)
    {
        i->next=NULL;
        i->prior=NULL;
        last=i;
        return(i);
    }
    p=top;
    old=NULL;
    while(p){
        if(strcmp(p->name,i->name)<0)
        {
            old=p;
            p=p->next;
        }
        else
        {
            if(p->prior)
            {
            p->prior->next=i;
            i->next=p;
            i->prior=p->prior;
            p->prior=i;
            return(top);
            }
            i->next=p;
            i->prior=NULL;
            p->prior=i;
            return(i);
    }
    }
    old->next=i;
    i->next=NULL;
    i->prior=old;
    last=i;
    return(start);
}
delete()
{
    struct address *info,*find();
    char s[80];
   
    printf("\t:请输入姓名:");
    gets(s);
    info=find(s);
    if(info)
    {
        if(start==info)
        {
            start=info->next;
            if(start)
                start->prior=NULL;
            else
                last=NULL;
        }
            
   
         else
        {
            info->prior->next=info->next;
            if(info!=last) info->next->prior=info->prior;
            else last=info->prior;
        }
    free(info);
    }
}
struct address *find(name)
    char *name;
{

    struct address *info,*start;
    info=start;
    while(info)
    {
        if(!strcmp(name,info->name))
            return(info);
        info=info->next;
        }
    printf("\t 未能找到此姓名!\n");
        return(NULL);
    }
list()
{
    register int t;
    struct address *info;
    info=start;
    while(info)
    {
        display(info);
        info=info->next;
    }
    printf("\n\n");
}
void display(info)
struct address *info;
{
    printf("\t%s\n",info->name);
    printf("\t%s\n",info->street);
    printf("\t%s\n",info->city);
    printf("\t%s\n",info->province);
    printf("\t%s\n",info->zip);
    printf("\n\n");
}
void search()
{
    char name[40];
    struct address *info,*find();
    printf("\t请给要找的姓名:");
    gets(name);
    if(!(info=find(name)))
        printf("\t未找到!");
    else
        display(info);
}
void save()
{
    register int t;
    struct address *info;
    FILE *fp;
    if((fp=fopen("mlist","wb"))==NULL)
    {
        printf("\t文件不存在!");
        exit(0);
    }
    printf("\t正在存入文件\n");
    info=start;
    while(info)
    {
        fwrite(info,sizeof(struct address),1,fp);
        info=info->next;
    }
    fclose(fp);

}
void load()
{
    register int;
    struct    address *info,*temp=NULL;
    FILE *fp;
    if((fp=fopen("mlist","wb"))==NULL)
    {
        printf("\t文件打不开!");
        exit(1);
    }
    while(start)
    {
        info=start->next;
        free(info);
        start=info;
    }
    printf("\t正在装入文件!\n");
    start=(struct address *)malloc(sizeof(struct address));
    if(!start)
    {
        printf("\t内存已用完!\n");
        return;
    }
    info=start;
    while(!feof(fp))
    {
        if(1!=fread(info,sizeof(struct address),1,fp))
            break;
        info->next=(struct address *)malloc(sizeof(struct address));
        if(!info->next)
        {
            printf("\t内存已用完!\n");
            return;
        }
        info->prior=temp;
        temp=info;
        info=info->next;
    }
    temp->next=NULL;
    last=temp;
    start->prior=NULL;
    fclose(fp);
}

编译之后 出现的是有大概14个warning  and  1error
暂时不管warning  只看error
是这样子的  
红色部分提示 是  
error C2040: 'dls_store' : 'struct address *()' differs in levels of indirection from 'struct address ()'
改如何解决
 请高手支招


图片附件: 游客没有浏览图片的权限,请 登录注册














搜索更多相关主题的帖子: 链表 c语言 练习 纠结 
2010-11-15 16:39
快速回复:一个纠结的c语言问题(双向链表练习)
数据加载中...
 
   



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

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