| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 384 人关注过本帖
标题:啊呀!!谁来帮帮我啊 !!!
只看楼主 加入收藏
见于心
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-7-13
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
啊呀!!谁来帮帮我啊 !!!
看不懂!指针还没学到!哪位大大能帮我翻译成数组的啊?万分感谢!!!

#define LEN sizeof(struct TXJL)
#define NULL 0
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
struct PHONE
{  int firstNum;
   long secondNum;
};
struct TXJL
{
    char name[10];
    struct PHONE phone;
    struct TXJL *next;
};
void Help()
{
  printf("---------系统声明----------\n");
  printf("本系统是由。。。。。。开发\n");
  printf("欢迎批评指正.联系邮件:。。。。。。。。\n");
}
void fmenu()
{   system("cls");
    printf("通讯录管理系统\n");
    printf("1.输入初始数据录入\n");
    printf("2.文件载入数据\n");
    printf("3.表头插入数据\n");
    printf("4.表尾插入数据\n");
    printf("5.删除数据\n");
    printf("6.显示数据\n");
    printf("7.查找数据\n");
    printf("8.保存数据到文件\n");
    printf("0.退出\n");
    printf("Auducy!\n");
}
struct TXJL *create_txl()
 { struct TXJL *head,*tail,*p;
    int i=0;head=tail=NULL;
    while (1)
    {  p=(struct TXJL*)malloc(LEN);
        printf("输入第%d个姓名:",i+1);
       scanf("%s",p->name);
       if(!strcmp(p->name,"#"))break;
        printf("输入其手机号码前3位:");
        scanf("%d",&p->phone.firstNum);
        printf("输入其手机号码后8位:");
        scanf("%ld",&p->phone.secondNum);
       p->next=NULL;
       if(i==0)
       { head=tail=p;i++;}
       else
       {tail->next=p;
       tail=p ;
       i++;
       }
    };
    free(p);
    return (head);
}
void print_txl(struct TXJL*head)
 {   struct  TXJL*p;
 p=head;
 if (head!=NULL)
     do
     {
         printf("%s-----%d-----%ld\n",p->name,p->phone.firstNum,p->phone.secondNum);
         p=p->next;
     }while(p!=NULL);
 }
void outData(struct TXJL*p)
{  
    printf("%s-----%d-----%8d\n",p->name,p->phone.firstNum,p->phone.secondNum);
}
struct TXJL *read_txl(char*pFileName)
{  
   int i=0;
   struct TXJL *p;
   struct TXJL *tail;
   struct TXJL *head;
   FILE*fp;
   fp=fopen(pFileName,"r");
   if(fp==NULL)
   {
       printf("Cannot open file!\n");
       exit(0);
   }
   else
   {do
      { p=(struct TXJL*)malloc(LEN);
       fscanf(fp,"%s%3d%ld",&(p->name),&(p->phone.firstNum),&(p->phone.secondNum));
       p->next=NULL;
       if(!strcmp(p->name,"#"))break;
        if(i==0)
        { head=tail=p;
        i++;
        }
        else  
        {tail->next=p;
         tail=p;
         i++;
        }
      }while(1);
       free(p);
       return(head);
   }
}
struct TXJL*insert_txl1(struct TXJL*head,struct TXJL*p)
{  struct TXJL*q=head;
   struct TXJL*pre;
   p->next=NULL;
   if(head==NULL)head=p;
   else
   {   while(q->next!=NULL)
   {   pre=q;
        q=q->next;
   }
   q->next=p;
   }
   return (head);
}
struct TXJL *insert_txl2(struct TXJL *head,struct TXJL*p)
{  p->next=NULL;
    if(head==NULL)head=p;
    else
    {  p->next=head;
         head=p;
    }
    return(head);
}
struct TXJL*delete_txl(struct TXJL*head,char*pName)
{   struct TXJL*q,*p=head;
     if(!strcmp(pName,head->name))
     {head=head->next;
     free(p);
     }
     else
     {  do
     {q=p;
     if(!strcmp(pName,p->name))break;
     p=p->next;
     }while(p->next!=NULL);
     if((p!=NULL)&&!strcmp(pName,p->name))
     { q->next=p->next;
     free(p);
     }
     else printf("不存在姓名是%s的结点!\n",pName);
     }
     return(head);
}
struct TXJL*find_txl1(struct TXJL*head,char *pName)
{  struct TXJL*p;
   p=head;
   while((p!=NULL)&&strcmp(p->name,pName))
       p=p->next;
       if(p) return(p);
       else return(NULL);
}
struct TXJL*find_txl2(struct TXJL*head,long n)
{ struct TXJL *p;
  p=head;
  while((p!=NULL)&&(p->phone.secondNum!=n))
   p=p->next;
  if(p) return(p);
  else return(NULL);
}
void write_txl(struct TXJL*head,char *pFileName)
 {
     FILE*fp;
     struct TXJL *p;
     p=head;
     fp=fopen(pFileName,"w");
     if(head!=NULL)
    do
         {fprintf(fp,"%10s  %d  %ld\n",p->name,p->phone.firstNum,p->phone.secondNum);
            p=p->next;     
         }while(p!=NULL);
         fprintf(fp,"# ");
         fclose(fp);
}
void main()
{  char str[80];
   struct TXJL*head,*p;
   int x,k,n;
   Help();
   fmenu();
   scanf("%d",&x);
   while(x!=0)
   {   
        switch(x)
        {  case 1:
                 head=create_txl();
                 write_txl(head,"D:\\TXJL.txt");
                 break;
           case 2:
                  printf("Auducy!\n");
                  head=read_txl("D:\\TXJL.txt");
                  break;
           case 3:
                  printf("Auducy!\n");
                  printf("输入插入结点的值:\n");
                  p=(struct TXJL*)malloc(LEN);
                  printf("输入插入结点的姓名:");
                  scanf("%s",p->name);
                  printf("输入其手机号码前3位:");
                  scanf("%d",&p->phone.firstNum);
                  printf("输入其手机号码后8位:");
                  scanf("%ld",&p->phone.secondNum);
                  head=insert_txl2(head,p);
                  break;
           case 4:
                  printf("输入插入结点的值:\n");
                  p=(struct TXJL*)malloc(LEN);
                  printf("输入插入结点的姓名:");
                  scanf("%s",p->name);
                  printf("输入其手机号码前3位:");
                  scanf("%d",&p->phone.firstNum);
                  printf("输入其手机号码后8位:");
                  scanf("%ld",&p->phone.secondNum);
                  head=insert_txl1(head,p);
                  break;
           case 5:
                  getchar();
                  printf("输入删除结点的姓名:\n");
                  scanf("%s",str);
                  head=delete_txl(head,str);
                  break;
           case 6:
                  head=read_txl("D:\\TXJL.txt");
                  print_txl(head);
                  break;
           case 7:
                  system("cls");
                  printf("1.按姓名查找\n");
                  printf("2.按电话查找\n");
                  scanf("%d",&k);
                  if(k==1)
                  {  getchar();
                     printf("输入要查找的姓名:\n");
                     scanf("%s",str);
                     p=find_txl1(head,str);
                     if(p)
                     { printf("存在,输出如下:\n");
                       outData(p);
                     }
                  }
                    else
                    { printf("输入要查找的电话号码后8位:\n");
                      scanf("%ld",&n);
                      p=find_txl2(head,n);
                      if (p)
                      { printf("存在,输出如下:\n");
                         outData(p);}
                    }
                    break;
           case 8:
                  write_txl(head,"D:\\TXJL.txt");
                  break;
           case 9:
                  exit(0);
        }
        printf("按任意键继续\n");
         printf("Auducy!\n");
        getchar();
        getchar();
        system("cls");
        fmenu();
        scanf("%d",&x);
   }
}
搜索更多相关主题的帖子: include system 开发 
2010-07-15 14:05
jmchang
Rank: 2
等 级:论坛游民
帖 子:16
专家分:66
注 册:2010-7-14
收藏
得分:6 
找高手吧,没找到错误出现在那里。

[url=http://www.]抛光蜡[/url]
2010-07-17 16:43
vs_inzaghi
Rank: 5Rank: 5
来 自:湖北
等 级:职业侠客
威 望:1
帖 子:303
专家分:364
注 册:2009-8-17
收藏
得分:6 
……大哥,你这貌似是个链表啊……
貌似不能把里面的指针用数组改写的……要是没指针,你这链表就成了碎片了……

我很懒,但我讨厌别人说我懒……
2010-07-20 02:10
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:6 
呵呵,确实呀

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-22 09:36
快速回复:啊呀!!谁来帮帮我啊 !!!
数据加载中...
 
   



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

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