#include stdio.h
我们提供的服务有:成都网站设计、网站建设、微信公众号开发、网站优化、网站认证、洛宁ssl等。为近千家企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的洛宁网站制作公司
#include stdlib.h
#include string.h
#include conio.h
#define N 100 void input();//添加新用户函数
void amend();//修改用户信息函数
void delete_client();//删除用户信息函数
void demand_client();//用户信息查询函数
void collect_telephone();//用户信息汇总函数
void save_client(struct telephone message);//保存函数
void demand_name();//按用户名查询
void demand_telephone();//按电话号码查询
struct telephone
{
char client_name[20];
char client_address[30];
char client_telephone[15];
}; //添加新用户函数
void input()
{
struct telephone message;
char reply='y';
char save='y';
while (reply=='y')
{ printf("用户姓名:");
scanf("%s",message.client_name);
printf("电话号码:");
scanf("%s",message.client_telephone); save_client(message);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //保存函数
void save_client(struct telephone message)
{
FILE *fp;
fp=fopen("message.dat","a+");
if (fp!=NULL)
{
fwrite(message,sizeof(struct telephone),1,fp);
}
else
{
printf("\n打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
} //修改用户信息函数
void amend()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
char save='y';
int size=sizeof(struct telephone);
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入要修改的姓名:");
scanf("%s",amend_name);
while ((fread(message,size,1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("\n用户姓名:%s\n",message.client_name);
printf("\n电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
printf("修改用户信息:\n");
printf("\n用户姓名:");
scanf("%s",message.client_name); printf("\n电话号码:");
scanf("%s",message.client_telephone);
printf("\n要保存吗?(y/n):");
scanf(" %c",save);
if (save=='y')
{
fseek(fp,-size,1);
fwrite(message,sizeof(struct telephone),1,fp);
}
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //删除用户信息函数
void delete_client()
{
struct telephone message[N];
struct telephone temp_str;
struct telephone delete_str;
int i=0,j=0;
char reply='y';
char found='y';
char confirm='y';
char delete_name[20];
FILE *fp;
while (reply=='y')
{
system("cls");
fp=fopen("message.dat","r");
if (fp!=NULL)
{
i=0;
found='n';
printf("\n请输入姓名:");
scanf("%s",delete_name);
while ((fread(temp_str,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(delete_name,temp_str.client_name))==0)
{
found='y';
delete_str=temp_str;
}//查找要删除的记录
else
{
message[i]=temp_str;
i++;
}//将其它无关记录保存起来
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
if (found=='y')
{
printf("==========================================\n");
printf("用户姓名:%s\n",delete_str.client_name);
printf("电话号码:%s\n",delete_str.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息,按任意键返回……\n");
getchar();
break;
}
printf("确定要删除吗?(y/n):");
scanf(" %c",confirm);
if (confirm=='y')
{
fp=fopen("message.dat","w");
if (fp!=NULL)
{
for(j=0;ji;j++)
{
fwrite(message[j],sizeof(struct telephone),1,fp);
}
printf("记录已删除!!!\n");
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
}
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
}
//用户信息查询函数
void demand_client()
{
int choice=1;
while (choice!=3)
{
system("cls");
printf("电话查询菜单\n");
printf(" 1 按联系人姓名查询\n");
printf(" 2 按联系人电话号码查询\n");
printf(" 3 返回主菜单\n");
printf("请选择(1-3):");
scanf("%d%*c",choice);
if (choice3)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回菜单……\n");
getchar();
continue;
}
if (choice==1)
{
demand_name();
}
else if (choice==2)
{
demand_telephone();
}
}
} //按用户名查询
void demand_name()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入姓名:");
scanf("%s",amend_name);
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //按电话号码查询
void demand_telephone()
{
struct telephone message;
FILE *fp;
char telephone[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入电话号码:");
scanf("%s",telephone);
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(telephone,message.client_telephone))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此电话号码的有关信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //用户信息汇总函数
void collect_telephone()
{
struct telephone message;
FILE *fp;
fp=fopen("message.dat","r");
if (fp!=NULL)
{
system("cls");
printf("\n用户姓名\t\t电话号码\n");
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
printf("\n%-24s",message.client_name); printf("%-12s\n",message.client_telephone);
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("按任意键返回主菜单……\n");
getch();
} void main()
{
char choice[10]="";
int len=0;
while (choice[0]!='7')
{ printf("\t==========电话本号码查询系统=============\n"); printf("\t\t 1、添加新联系人\n");
printf("\t\t 2、修改联系人信息\n");
printf("\t\t 3、删除联系人信息\n");
printf("\t\t 4、联系人信息查询\n");
printf("\t\t 5、联系人信息汇总\n");
printf("\t\t 7、退出\n");
printf("\t=========================================\n");
printf("请选择(1-7):");
scanf("%s",choice);
len=strlen(choice);
if (len1)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回主菜单……\n");
getchar();
getchar();
continue;
} switch (choice[0]) {
case '1':
input();
break;
case '2':
amend();
break;
case '3':
delete_client();
break;
case '4':
demand_client();
break;
case '5':
collect_telephone();
break; default:
break;
}
}
}
#include stdio.h
#include stdlib.h
#include string.h
#include conio.h
#define N 100 void input();//添加新用户函数
void amend();//修改用户信息函数
void delete_client();//删除用户信息函数
void demand_client();//用户信息查询函数
void collect_telephone();//用户信息汇总函数
void save_client(struct telephone message);//保存函数
void demand_name();//按用户名查询
void demand_telephone();//按电话号码查询
struct telephone
{
char client_name[20];
char client_address[30];
char client_telephone[15];
}; //添加新用户函数
void input()
{
struct telephone message;
char reply='y';
char save='y';
while (reply=='y')
{ printf("用户姓名:");
scanf("%s",message.client_name);
printf("电话号码:");
scanf("%s",message.client_telephone); save_client(message);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //保存函数
void save_client(struct telephone message)
{
FILE *fp;
fp=fopen("message.dat","a+");
if (fp!=NULL)
{
fwrite(message,sizeof(struct telephone),1,fp);
}
else
{
printf("\n打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
} //修改用户信息函数
void amend()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
char save='y';
int size=sizeof(struct telephone);
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入要修改的姓名:");
scanf("%s",amend_name);
while ((fread(message,size,1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("\n用户姓名:%s\n",message.client_name);
printf("\n电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
printf("修改用户信息:\n");
printf("\n用户姓名:");
scanf("%s",message.client_name); printf("\n电话号码:");
scanf("%s",message.client_telephone);
printf("\n要保存吗?(y/n):");
scanf(" %c",save);
if (save=='y')
{
fseek(fp,-size,1);
fwrite(message,sizeof(struct telephone),1,fp);
}
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //删除用户信息函数
void delete_client()
{
struct telephone message[N];
struct telephone temp_str;
struct telephone delete_str;
int i=0,j=0;
char reply='y';
char found='y';
char confirm='y';
char delete_name[20];
FILE *fp;
while (reply=='y')
{
system("cls");
fp=fopen("message.dat","r");
if (fp!=NULL)
{
i=0;
found='n';
printf("\n请输入姓名:");
scanf("%s",delete_name);
while ((fread(temp_str,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(delete_name,temp_str.client_name))==0)
{
found='y';
delete_str=temp_str;
}//查找要删除的记录
else
{
message[i]=temp_str;
i++;
}//将其它无关记录保存起来
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
if (found=='y')
{
printf("==========================================\n");
printf("用户姓名:%s\n",delete_str.client_name);
printf("电话号码:%s\n",delete_str.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息,按任意键返回……\n");
getchar();
break;
}
printf("确定要删除吗?(y/n):");
scanf(" %c",confirm);
if (confirm=='y')
{
fp=fopen("message.dat","w");
if (fp!=NULL)
{
for(j=0;ji;j++)
{
fwrite(message[j],sizeof(struct telephone),1,fp);
}
printf("记录已删除!!!\n");
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
}
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
}
//用户信息查询函数
void demand_client()
{
int choice=1;
while (choice!=3)
{
system("cls");
printf("电话查询菜单\n");
printf(" 1 按联系人姓名查询\n");
printf(" 2 按联系人电话号码查询\n");
printf(" 3 返回主菜单\n");
printf("请选择(1-3):");
scanf("%d%*c",choice);
if (choice3)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回菜单……\n");
getchar();
continue;
}
if (choice==1)
{
demand_name();
}
else if (choice==2)
{
demand_telephone();
}
}
} //按用户名查询
void demand_name()
{
struct telephone message;
FILE *fp;
char amend_name[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入姓名:");
scanf("%s",amend_name);
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(amend_name,message.client_name))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此人信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //按电话号码查询
void demand_telephone()
{
struct telephone message;
FILE *fp;
char telephone[20];
char reply='y';
char found='y';
while (reply=='y')
{
found='n';
fp=fopen("message.dat","r+w");
if (fp!=NULL)
{
system("cls");
printf("\n请输入电话号码:");
scanf("%s",telephone);
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
if ((strcmp(telephone,message.client_telephone))==0)
{
found='y';
break;
}
}
if (found=='y')
{ printf("==========================================\n");
printf("用户姓名:%s\n",message.client_name); printf("电话号码:%s\n",message.client_telephone);
printf("==========================================\n");
}
else
{
printf("无此电话号码的有关信息!\n");
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("要继续吗?(y/n):");
scanf(" %c",reply);
}
printf("按任意键返回主菜单……\n");
getchar();
getchar();
} //用户信息汇总函数
void collect_telephone()
{
struct telephone message;
FILE *fp;
fp=fopen("message.dat","r");
if (fp!=NULL)
{
system("cls");
printf("\n用户姓名\t\t电话号码\n");
while ((fread(message,sizeof(struct telephone),1,fp))==1)
{
printf("\n%-24s",message.client_name); printf("%-12s\n",message.client_telephone);
}
}
else
{
printf("打开文件时出现错误,按任意键返回……\n");
getchar();
return;
}
fclose(fp);
printf("按任意键返回主菜单……\n");
getch();
} void main()
{
char choice[10]="";
int len=0;
while (choice[0]!='7')
{ printf("\t==========电话本号码查询系统=============\n"); printf("\t\t 1、添加新联系人\n");
printf("\t\t 2、修改联系人信息\n");
printf("\t\t 3、删除联系人信息\n");
printf("\t\t 4、联系人信息查询\n");
printf("\t\t 5、联系人信息汇总\n");
printf("\t\t 7、退出\n");
printf("\t=========================================\n");
printf("请选择(1-7):");
scanf("%s",choice);
len=strlen(choice);
if (len1)
{
printf("请输入1-6之间的整数\n");
printf("按任意键返回主菜单……\n");
getchar();
getchar();
continue;
} switch (choice[0]) {
case '1':
input();
break;
case '2':
amend();
break;
case '3':
delete_client();
break;
case '4':
demand_client();
break;
case '5':
collect_telephone();
break; default:
break;
}
}
}
这段代码没有问题
你需要检查一下链表的数据内容,在调用本函数前,用输出语句先遍历一下链表看一下内容吧,估计是建表有问题,或是输入的数据存储不正确。
"gotoxy()","moveto()"包含在#include conio.h中了.
转载一个程序给你:(ZT)
算法:将当前时间显示到屏幕,当时间发生变化时,清屏,显示新的时间(当有键盘操作时退出程序)。
显示时间格式:小时:分钟:秒
/* DEV C++ Win XP*/
#include stdio.h
#include stdlib.h
#include conio.h
#include time.h
typedef struct
{
int x;
int y;
}Point;
time_t now;
struct tm *pt,t1,t2;
int printpoint(Point p)
{
Point p1;
p1.x=p.x+2; p1.y=p.y+4;
gotoxy(p1.x,p1.y); printf("%c%c",2,2);
gotoxy(p1.x, p1.y+1); printf("%c%c",2,2);
p1.y+=4;
gotoxy(p1.x,p1.y); printf("%c%c",2,2);
gotoxy(p1.x,p1.y+1); printf("%c%c",2,2);
return 0;
}
int print0(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else
printf("%c%4s%c",2," ",2);
}
return 0;
}
int print1(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
printf("%5s%c"," ",2);
}
return 0;
}
int print2(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==6¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else if(i0i6)
printf("%5s%c"," ",2);
else
printf("%c",2);
}
return 0;
}
int print3(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==6¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else
printf("%5s%c"," ",2);
}
return 0;
}
int print4(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i6) printf("%c%4s%c",2," ",2);
else if(i==6)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else printf("%5s%c"," ",2);
}
return 0;
}
int print5(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==6¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else if(i0i6)
printf("%c",2);
else
printf("%5s%c"," ",2);
}
return 0;
}
int print6(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==6¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else if(i0i6)
printf("%c",2);
else
printf("%c%4s%c",2," ",2);
}
return 0;
}
int print7(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0) printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else printf("%5s%c"," ",2);
}
return 0;
}
int print8(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==6¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else printf("%c%4s%c",2," ",2);
}
return 0;
}
int print9(Point p)
{
int i=0;
for(;i13;i++)
{
gotoxy(p.x+1, p.y+i);
if(i==0¦¦i==6¦¦i==12)
printf("%c%c%c%c%c%c",2,2,2,2,2,2);
else if(i0i6)
printf("%c%4s%c",2," ",2);
else
printf("%5s%c"," ",2);
}
return 0;
}
int clear(Point p)
{
int i=0;
for(;i13;i++)
gotoxy(p.x,p.y+i); printf("%16s"," ");
return 0;
}
int printtime(Point p, int n)
{
int a,b;
Point pp;
a=n/10, b=n%10;
pp.x=p.x+8, pp.y=p.y;
switch(a)
{
case 0: print0(p); break;
case 1: print1(p); break;
case 2: print2(p); break;
case 3: print3(p); break;
case 4: print4(p); break;
case 5: print5(p); break;
}
switch(b)
{
case 0: print0(pp); break;
case 1: print1(pp); break;
case 2: print2(pp); break;
case 3: print3(pp); break;
case 4: print4(pp); break;
case 5: print5(pp); break;
case 6: print6(pp); break;
case 7: print7(pp); break;
case 8: print8(pp); break;
case 9: print9(pp); break;
}
return 0;
}
int main()
{
Point phour, pmin, psec,point1,point2;
phour.x=9, pmin.x=32, psec.x=55;
phour.y=pmin.y=psec.y=7;
point1.x=25, point2.x=49;
point1.y=point2.y=7;
clrscr();
textbackground(BLUE);
textcolor(YELLOW);
now=time(0);
pt=localtime(now);
t1=*pt;
printtime(phour, t1.tm_hour);
printpoint(point1);
printtime(pmin, t1.tm_min);
printpoint(point2);
printtime(psec, t1.tm_sec);
while(1)
{
now=time(0);
pt=localtime(now);
t2=*pt;
if(t2.tm_sec!=t1.tm_sec)
{
t1=t2;
clrscr();
printtime(phour, t1.tm_hour);
printpoint(point1);
printtime(pmin, t1.tm_min);
printpoint(point2);
printtime(psec, t1.tm_sec);
}
if(bioskey(1)==0) continue;
else exit(0);
}
return 0;
}