看我的C语言编程-通讯录

到百度贴吧首页
新闻   网页   贴吧   知道   MP3   图片   视频   百科
    吧内搜索 | 帮助

看我的C语言编程-通讯录

1楼

#include <stdio.h>
#include <stdio.h>
#include <string.h>
#define maxlen 100
struct persons
{ char name[10];
 char addr[20];
 char phnum[10];
 }persons[maxlen];
;
;
;
typedef struct lnode{
 char name[10];
 char addr[20];
char phnum[10];
 struct lnode *next;
 }listnode,*linklist;
;
;
;
 linklist head=NULL,r=NULL;
 listnode  *s,*p0,*p1,*p2,*p3,*p4,*p5,*p6,*p7;
 int i;
 char name1[10],ch;
 char str1[20];
 FILE *fp; ;
void creat()
{   int j;
 long k;
 fp=fopen("people.txt","r+t");
 if(fp!=NULL)
 {for(i=1;i<maxlen;i++)
{ j=fgetc(fp);
 if(j==EOF)
 return;
 k=i-1;
 fseek(fp,k*sizeof(struct persons),0);
 fread(&persons[i],sizeof(struct persons),1,fp);
 s=(linklist)malloc(sizeof(listnode));
 strcpy(s->name,persons[i].name);
 strcpy(s->addr,persons[i].addr);
 strcpy(s->phnum,persons[i].phnum);
 if(head==NULL)
 head=s;
 else
 r->next=s;
 r=s;}
}
 else
 { fp=fopen("people.txt","w");  i=1;
     }
}
;
;
;
void List()
{ p1=head;
while(p1!=NULL)
   { printf("\n\n\tname:%s\n",p1->name);
     printf("\n\n\taddr:%s",p1->addr);
     printf("\n\n\tphnum:%s",p1->phnum);
     p1=p1->next;
    }
 }
;
;
;
void Delete()
{ printf("\n\n\tplease input the name:");
 gets(name1);  p4=head;
 if(strcmp(p4->name,name1)==0)
     {  p4=p4->next;
 head=p4;
     }
 else
     {  while(strcmp(p4->next->name,name1)!=0)
 p4=p4->next;
 p5=p4->next;
 p4->next=p5->next;
 free(p5);
 }
 }
;
;
;
void Find()
{   printf("\n\n\tplease input the name:");
  p0=head;
  gets(name1);
    while(strcmp(name1,p0->name)!=0&&p0!=NULL)
  p0=p0->next;
  if(p0==NULL)
  printf("\n\n\tIt is not exit in the addr-book!");
  else
      {  printf("\n\n\tname:%s\n",p0->name);
  printf("\n\n\taddr:%s",p0->addr);
  printf("\n\n\tphnum:%s",p0->phnum);
        }
}
;
;
;
void Input()
{ s=(linklist)malloc(sizeof(listnode));
     printf("\n\n\tplease input the sb's meg:");
      printf("\n\n\t\tname:");
 scanf("%s",s->name);
 printf("\n\n\t\tAddr:");
 scanf("%s",s->addr);
 printf("\n\n\t\tphnum:");
 scanf("%s",s->phnum);
 if(head==NULL)
 head=s;
 else
 r->next=s;
 r=s;
}
;
;
;
void Alter()
  {
 int j;
 printf("\n\n\tPlease input the name:");
     gets(name1);
 p3=head;
 while(strcmp(name1,p3->name)!=0&&p3!=NULL)
 p3=p3->next;
 if(p3==NULL)
 printf("\n\n\tIt is not exit in the addr-book!");
 else
     {  printf("\n\n\tplease input the new meg!");
 printf("\n\n\t\tname:");
 scanf("%s",name1);
 strcpy(p3->name,name1);
 printf("\n\n\t\tAddr:");
 scanf("%s",name1);
 strcpy(p3->addr,name1);
 printf("\n\n\t\tphnum:");
 scanf("%s",name1);
 strcpy(p3->phnum,name1);
      }
}
;
;
;
void Save()
{ int j;
 fp=fopen("people.txt","w");
 for(p2=head,j=0;p2!=NULL;j++,p2=p2->next)
 {  strcpy(persons[j].name,p2->name);
 strcpy(persons[j].addr,p2->addr);
 strcpy(persons[j].phnum,p2->phnum);
 fwrite(&persons[j],sizeof(struct persons),1,fp);
 }
}
;
;
;

void main()
{ creat();
 do
    {printf("\n\t***********************************************\n");
    printf("\n\n\tWELCOME TO USE XIESHENGQING's Address book\n");
    printf("\n\t**********************************************\n");
 printf("\n\n\t\tPlease make a choice below:");
 printf("\n\t\t1.List all the meg");
 printf("\n\t\t2.Delete a piece of meg");
 printf("\n\t\t3.Find a piece of meg");
 printf("\n\t\t4.Add a piece of meg");
 printf("\n\t\t5.Alter a piece of meg");
 printf("\n\t\t6.Save and Quit");
 printf("\n\t\t7.Create an address book");
 printf("\n\n\n");
 printf("\tInput Your Choice:");
 ch=getche();
 switch(ch)
       {   case '1':  List();         break;
           case '2':  Delete();
        break;
           case '3':  Find();
        break;
    case '4':  Input();
        break;
    case '5':  Alter();
        break;
    case '7':  Save();
break;
    case '6':  creat();
        fclose(fp);
exit(0);
        break;
    default:
     printf("\n\t********************************************\n");
     printf("\n\t        The num should 1-4!!!              \n");
     printf("\n\t********************************************\n");
     break;
 }
     }while(1);
     }

2楼

本程序有一缺陷,就是限制通讯录的大小,可以调用calloc()函数解决.不妨试一下哦.

3楼

靠 看不懂呀
219.135.90.*

4楼

请问一下,怎样用那个结构数组?
能就通讯录给一个例子吗?
谢了!

222.181.112.*

5楼

我用回死
222.190.105.*

6楼

用C++吧
61.177.74.*

7楼

能再帮我编一个程序吗
218.56.106.*

8楼

对初学者来说不怎么明白
像天书

59.41.74.*

9楼

我有大量学习编程的资料和视频,需要的朋友.......
加我Q:350776162

10楼

赌东道赌东道赌东道的
60.166.143.*

11楼

写的不错!!!!
但是查找方式单一了点 要有多种查询方式更好了

218.75.45.*

12楼

太强了,崇拜你啊
218.2.115.*

13楼

崇拜你~~~~````
能不能把你的课程报告也写一下呢?
急需。。。。

221.204.229.*

14楼

能不能用hash做一个
202.101.244.*

15楼

帮我编个程序好吗?编好了 发到我QQ上547662808。有急用明天就要,谢谢啊
202.101.244.*

16楼

是通讯录管理的程序,最好用文件编547662808
218.25.36.*

17楼

帮帮忙啊,帮忙画一下通讯录的流程图呗,谢了,帮忙发到邮箱weilingtianxu@163.com谢拉
61.178.57.*

18楼

有些模块没啊
还有吗?

61.235.80.*

19楼

各位大哥,有谁会用共用体编写通讯录程序的哦,请你们快来救救我哦.
58.62.86.*

20楼

kgf
58.62.86.*

21楼

主要内容:1.将本班学生的信息(每个学生至少包括学号、姓名、科目成绩(三门)、学分),存放于文件student.txt。要求编写函数fun找出所有及格的同学,并将他们的信息存放在文件score.txt中,并且输出结果。
附:stduent.txt内容:(可根据实际情况输入)
学号 姓名 高数成绩
学分
0101 小张 81.5
0102 小李 62.0
0103 小王 77.5
0104 小周 96.0
0105 小刘 55.0
0201 小胡 42.0
0202 小赵 69.0
0301 小何 80.0
0302 小黄 60.0
0303 小杨 56.0

2.编写函数backupdata实现将student.txt内容复制到备份文件backup.txt中,要求不能使用该两个文件以外的任何文件。

60.2.17.*

22楼

你写的还不错
218.19.152.*

23楼

我有大量学习编程的资料和视频,需要的朋友....... 

http://www.javavc.com

24楼

哇,,是谁写的?

25楼

初学C语言!上来请教请教!
谁可搞些符合我现况的程序吗?我来教作业的!~~~~

219.133.89.*

26楼

good!
192.18.43.*

27楼

This program is able to support unicode?
221.2.53.*

28楼

它怎么看我这么眼熟,我却不认识它呢?
221.201.154.*

29楼

怎么程序我看着这么眼熟
59.72.4.*

30楼

不错,比我好多了!

发表回复

内 容:
用户名:
  
©2010 Baidu 贴吧协议  意见反馈