| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 690 人关注过本帖
标题:[求助]有用C语言的帮下忙阿!我遇到了一个难题!
取消只看楼主 加入收藏
tracn
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-9-14
收藏
 问题点数:0 回复次数:0 
[求助]有用C语言的帮下忙阿!我遇到了一个难题!

大家好,我们做c语言的课程设计,我选的是通讯录系统。总是找不出错误,有谁懂c 语言的帮我看一下好吗?用链表做的。大家帮个忙啊!跪谢!以下是我写的源程序!

#include <stdio.h>
#define M sizeof(struct mingdan)
#define H p1->comm[i].name,p1->comm[i].phone,p1->comm[i].addrss,p1->comm[i].qq,p1->comm[i].email
#define T p->comm[i].name,p->comm[i].phone,p->comm[i].addrss,p->comm[i].qq,p->comm[i].email
#define N 10
struct mingdan
{
char name[20];
char phone[20];
char addrss[20];
char qq[20];
char email[20];
struct mingdan *next;
};
struct mingdan comm[N];
struct mingdan *head=NULL;
void input();
main()
{
char t;
for(;;)
{
printf(" *************Tong Xun Lu*************\n\n");
printf(" -------------------------------------\n");
printf(" [0]---Input information\n");
printf(" [1]---Modify info\n");
printf(" [2]---Increase info\n");
printf(" [3]---Delete info\n");
printf(" [4]---Search info\n");
printf(" [5]---Display all\n");
printf(" [6]---Exit\n");
printf("Please choose:");
scanf("%c",&t);
switch(t)
{
case '0':input();break;
case '6':exit(1);
}
}
}
void input()
{
char flag;
int i,t=0;
FILE *fp;
struct mingdan *p1,*p2;
head=p2=p1=(struct mingdan *)malloc(M);
if((fp=fopen("C:\\list.txt","at+"))==NULL)
{
printf("Can't open this file!!!");
getch();
exit(1);
}
fprintf(fp,"%s","Name Telephone Addrss QQ E-mail");
fprintf(fp,"%s","~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("Input num name score of math,c and english:\n");
scanf("%s%s%s%s%s",H);
printf("Input info:\n");
printf("Name Phone Addrss QQ E-mail\n");
printf("-------------------------------\n");
for(i=t;i<N;i++)
{
printf("Input the next infomation:\n");
scanf("%s%s%s%s%s",H);
t++;

if(fwrite(&comm,sizeof(struct mingdan),1,fp)!=1)
{
printf("Error!!!");
getch();
exit(1);
}
else printf("Success!!!\n");
fprintf(fp,"\n");
p2->next=p1;
p2=p1;
}
p2->next=NULL;
}
void delete()
{
FILE *fp;
int i;
struct mingdan *p,*p0;
char name[20];
if((fp=fopen("c:\\list.txt","rt"))==NULL)
{
printf("Open this file failed!!!");
getch();
exit(1);
}
for(i=0;i<N;i++)
{
if(fread(&comm[i],sizeof(struct mingdan),N,fp)!=1)
printf("Read file error!!!");
}
fcolse(fp);
if(head==NULL) {printf("There isn't information in system,couldn't delete!!!\n"); getch(); return;}
printf("Input the name will be delete:\n");
scanf("%s",&name);
p0=head;
if(*(p0->name)==name)
{
head=p0->next;
free(p0);
printf("Delete success!!!\n");
getch();
return;
}
p=p0->next;
while(p!=NULL)
{
if(*(p->name)==name)
{
p0->next=p->next;
free(p);
printf("Delete success!!!\n");
getch();
return;
}
p0=p;
p=p->next;
}
printf("Haven't information of this name!!!\n");
getch();
return;
}
/*注意字符串比较大小*/
void insert()
{
FILE *fp;
int i;
struct mingdan *p,*p0;
if((fp=fopen("c:\\list.txt","rt"))==NULL)
{
printf("Open this file failed!!!");
getch();
exit(1);
}
for(i=0;i<N;i++)
{
if(fread(&comm[i],sizeof(struct mingdan),N,fp)!=1)
printf("Read file error!!!");
}
fcolse(fp);
p=(struct mingdan*)malloc(N);
printf("Input the information that will be insert name phone Addrss QQ E-mail:\n");
scanf("%s %s %s %s %s",T);
p->next=NULL;
if(head==NULL)
{
head=p;
printf("Insert success!!!\n");
getch();
return;
}
p0=head;
if(p0->name>p->name)
{
p->next=head;
head=p;
printf("Insert success!!!\n");
getch(); return;
}
while(p0->next!=NULL&&p0->next->name<p->name)
p0=p0->next;
if(p0->next->name==p->name)
{
free(p);
printf("Have a same name,insert fail!!!\n");
getch(); return;
}
else if(p0->next==NULL)
{
p0->next=p;
p->next=NULL;
printf("Insert success!!!\n");
getch();
return;
}

p->next=p0->next;
p0->next=p;
printf("Insert sucess!!!\n");
getch();
}
void modify()
{
FILE *fp;
int i;

char name[9];
if((fp=fopen("c:\\list.txt","rt"))==NULL)
{
printf("Open this file failed!!!");
getch();
exit(1);
}
for(i=0;i<N;i++)
{
if(fread(&comm[i],sizeof(struct mingdan),N,fp)!=1)
printf("Read file error!!!");
}
fcolse(fp);
struct mingdan *p=head;
printf("Input name:\n");
scanf("%s",name);
while(p!=NULL&&strcmp(p->name,name))
p=p->next;
if(p!=NULL)
{
printf("%s%s%s%s%s",T);
printf("Input num name score of math,c and english:\n");
scanf("%s %s %s %s %s",T);
printf("Modify success!!!");
}
else printf("Haven't info!!!");
getch();
}
void search()
{
FILE *fp;
int i;
if((fp=fopen("c:\\list.txt","rt"))==NULL)
{
printf("Open this file failed!!!");
getch();
exit(1);
}
for(i=0;i<N;i++)
{
if(fread(&comm[i],sizeof(struct mingdan),N,fp)!=1)
printf("Read file error!!!");
}
fcolse(fp);
struct mingdan *p=head;
char name[9];
printf("Input name:\n");
scanf("%s",name);
while(p!=NULL&&strcmp(p->name,name))
p=p->next;
if(p!=NULL)
{
printf("Name Phone Addrss QQ E-mail");
printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
printf("%s%s%s%s%s",T);
}
getch();
}
void display(struct mingdan *p)
{
int i;
FILE *fp;
if((fp=fopen("c:\\list.txt","rt"))==NULL)
{
printf("Open this file failed!!!");
getch();
exit(1);
}
for(i=0;i<N;i++)
{
if(fread(&comm[i],sizeof(struct mingdan),N,fp)!=1)
printf("Read file error!!!");
}
fcolse(fp);
printf("Name Phone Addrss QQ E-mail\n");
while(p!=NULL)
{
printf("%s %s %s %s",T);
p=p->next;
}
}

搜索更多相关主题的帖子: C语言 难题 define 通讯录 课程 
2006-09-14 11:42
快速回复:[求助]有用C语言的帮下忙阿!我遇到了一个难题!
数据加载中...
 
   



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

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