| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 880 人关注过本帖
标题:[求助]C语言课程设计的通讯录
只看楼主 加入收藏
feng1q2q3q
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-6-21
收藏
 问题点数:0 回复次数:0 
[求助]C语言课程设计的通讯录

C语言课程设计的通讯录啊~~~
不知道哪里出错啦,应该是主函数的~~~请众位高人看看那里错了~~~请指点指点~~~~~~~(还有一些子函数没遍完的)
程序如下:
#include <stdio.h>
#define N 50
struct address
{
char name[20];
char city[15];
char email[20];
unsigned long phone;
unsigned long zip;
}stu[N];
void input()
{
FILE *fp;
int i;
fp=fopen("txl","wb");
for(i=0;i<N;i++)
{
printf("Input the name(Input -1 return):\n");
scanf("%s",stu[i].name);
if(stu[i].name=="-1")
break;
printf("Input the city:\n");
scanf("%s",stu[i].city);
printf("Input the email:\n");
scanf("%s",stu[i].email);
printf("Input the phone:\n");
scanf("%ld",&stu[i].phone);
printf("Input the zip:\n");
scanf("%ld",&stu[i].zip);
fwrite(&stu[i],sizeof(struct address),1,fp);
}
fclose(fp);
}
void read()
{
FILE *fp;
int i;
if((fp=fopen("txl","rb"))==NULL)
{
printf("Can not to open the txl.\n");
exit(1);
}
printf("Name City Email Phone Zip ");
for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++)
{
printf("%15s%15s%20s%15ld%10ld\n",stu[i].name,stu[i].city,stu[i].email,stu[i].phone,stu[i].zip);
}
fclose(fp);
}
void sort()
{
FILE *fp;
int i,j;
struct address t;
fp=fopen("txl","rb");
for(i=0;i<N-1;i++)
{
if(fread(&stu[i+1],sizeof(struct address),1,fp)==0)
break;
for(j=i+1;fread(&stu[j],sizeof(struct address),1,fp)!=0&&j<N;j++)
if(strcmp(stu[i].name,stu[j].name)<0)
{
t=stu[i];
stu[i]=stu[j];
stu[j]=t;
}
}
printf("Name City Email Phone Zip \n");
for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++)
printf("%15s%15s%20s%15ld%10ld\n",stu[i].name,stu[i].city,stu[i].email,stu[i].phone,stu[i].zip);
fclose(fp);
}
void append()
{
FILE *fp;
int i,sum=0;
fp=fopen("txl","rb");
for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++)
sum+=1;
fclose(fp);
fp=fopen("txl","ab");
for(i=sum;i<N;i++)
{
printf("Input the name(Input -1 return):\n");
scanf("%s",stu[i].name);
if(stu[i].name=="-1")
break;
printf("Input the city:\n");
scanf("%s",stu[i].city);
printf("Input the email:\n");
scanf("%s",stu[i].email);
printf("Inpute the phone:\n");
scanf("%ld",&stu[i].phone);
printf("Inpute the zip:\n");
scanf("%ld",&stu[i].zip);
fwrite(&stu[i],sizeof(struct address),1,fp);
}
fclose(fp);
}
void rejigger()
{
}
void find()
{
FILE *fp;
int i,j;
char s[16];
printf("Input the name:\n");
gets(s);
fp=fopen("txl","rb");
for(i=0;fread(&stu[i],sizeof(struct address),1,fp)!=0&&i<N;i++)
if(strcmp(stu[i].name,s)==0)
{
printf("Name City Email Phone Zip \n");
printf("%15s%15s%20s%15ld%10ld",stu[i].name,stu[i].city,stu[i].email,stu[i].phone,stu[i].zip);
}
fclose(fp);
}
void backup()
{
FILE *fp1,*fp2;
int i;
fp1=fopen("txl","rb");
fp2=fopen("txl2","wb");
for(i=0;fread(&stu[i],sizeof(struct address),1,fp1)!=0&&i<N;i++)
fwrite(&stu[i],sizeof(struct address),1,fp2);
fclose(fp1);
fclose(fp2);
printf("The backup was done!\n");
}
void delete()
{

}
main()
{
int a;
printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf(" * * * *\n");
printf(" * * * *\n");
printf(" * * (1)Input the data * *\n");
printf(" * * (2)Read the txl * *\n");
printf(" * * (3)Sort by name * *\n");
printf(" * * (4)Append the data * *\n");
printf(" * * (5)Rejigger the data * *\n");
printf(" * * (6)Find the data * *\n");
printf(" * * (7)Backup the data * *\n");
printf(" * * (8)Delete the data * *\n");
printf(" * * (0)Exit * *\n");
printf(" * * * *\n");
printf(" * * * *\n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf(" * * * * * * * * * * * * * * * * * * * * * * * * *\n");
printf("Input 0-8:\n");
for(;;)
{
scanf("%d",&a);
switch (a)
{
case 1: input();break;
case 2: read();break;
case 3: sort();break;
case 4: append();break;
case 5: rejigger();break;
case 6: find();break;
case 7: backup();break;
case 8: delete();break;
case 0: {
printf("* * * * * * * * * * * * * * * * * * * * *");
printf("* *");
printf("* Good by~~~ *");
printf("* *");
printf("* * * * * * * * * * * * * * * * * * * * *");
}break;
}
getch();
}
}

[此贴子已经被作者于2007-6-21 21:53:32编辑过]

搜索更多相关主题的帖子: C语言课程 通讯录 name Input 
2007-06-21 21:51
快速回复:[求助]C语言课程设计的通讯录
数据加载中...
 
   



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

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