這段代碼沒(méi)有問(wèn)題
創(chuàng)新互聯(lián)是專業(yè)的遵化網(wǎng)站建設(shè)公司,遵化接單;提供成都做網(wǎng)站、成都網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè),網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行遵化網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
你需要檢查一下鏈表的數(shù)據(jù)內(nèi)容,在調(diào)用本函數(shù)前,用輸出語(yǔ)句先遍歷一下鏈表看一下內(nèi)容吧,估計(jì)是建表有問(wèn)題,或是輸入的數(shù)據(jù)存儲(chǔ)不正確。
#include"stdio.h"#include"string.h"#include"stdlib.h"typedefstruct{//通訊錄結(jié)點(diǎn)類型charnum[5];//編號(hào)charname[9];//姓名charsex[3];//性別charphone[13];//電話charaddr[31];//地址}DataType;typedefstructnode{//結(jié)點(diǎn)類型定義DataTypedata;//結(jié)點(diǎn)數(shù)據(jù)域structnode*next;//結(jié)點(diǎn)指針域}ListNode;typedefListNode*LinkList;LinkListhead;ListNode*p;//函數(shù)說(shuō)明intmenu_select();LinkListCreateList(void);voidInsertNode(LinkListhead,ListNode*p);ListNode*ListFind(LinkListhead);voidDelNode(LinkListhead);voidprintList(LinkListhead);//主函數(shù)voidmain(){for(;;){switch(menu_select()){case1:printf("**********************************\n");printf("*通訊錄鏈表的建立*\n");printf("**********************************\n");head=CreateList();break;case2:printf("**********************************\n");printf("*通訊者信息的添加*\n");printf("**********************************\n");printf("編號(hào)(4)姓名(8)性別(3)電話(11)地址(31)\n");printf("*************************************\n");p=(ListNode*)malloc(sizeof(ListNode));//申請(qǐng)新結(jié)點(diǎn)scanf("%s%s%s%s%s",p-data.num,p-data.name,p-data.sex,p-data.phone,p-data.addr);InsertNode(head,p);break;case3:printf("***********************************\n");printf("*通訊錄信息的查詢*\n");printf("***********************************\n");p=ListFind(head);if(p!=NULL){printf("編號(hào)姓名性別聯(lián)系電話地址\n");printf("--------------------------------------------------\n");printf("%s,%s,%s,%s,%s\n",p-data.num,p-data.name,p-data.sex,p-data.phone,p-data.addr);printf("---------------------------------------------------\n");}elseprintf("沒(méi)有查到要查詢的通訊者!\n");break;case4:printf("***********************************\n");printf("*通訊錄信息的刪除*\n");printf("***********************************\n");DelNode(head);//刪除結(jié)點(diǎn)break;case5:printf("************************************\n");printf("*通訊錄鏈表的輸出*\n");printf("************************************\n");printList(head);break;case0:printf("\t再見(jiàn)!\n");return;}}}/*******************//*菜單選擇函數(shù)程序*//***************************/intmenu_select(){intsn;printf("通訊錄管理系統(tǒng)\n");printf("===================\n");printf("1.通訊鏈表的建立\n");printf("2.通訊者結(jié)點(diǎn)的插入\n");printf("3.通訊者結(jié)點(diǎn)的查詢\n");printf("4.通訊者結(jié)點(diǎn)的刪除\n");printf("5.通訊錄鏈表的輸出\n");printf("0.退出管理系統(tǒng)\n");printf("==========================\n");printf("請(qǐng)選擇0-5:");for(;;){scanf("%d",sn);if(sn5)printf("\n\t輸入錯(cuò)誤,重選0-5:");elsebreak;}returnsn;}/**************************//*用尾插法建立通訊錄鏈表函數(shù)*//**************************/LinkListCreateList(void){//尾插法建立帶頭結(jié)點(diǎn)的通訊錄鏈表算法LinkListhead=(ListNode*)malloc(sizeof(ListNode));//申請(qǐng)頭結(jié)點(diǎn)ListNode*p,*rear;intflag=0;//結(jié)束標(biāo)志置0rear=head;//尾指針初始指向頭結(jié)點(diǎn)while(flag==0){p=(ListNode*)malloc(sizeof(ListNode));//申新結(jié)點(diǎn)printf("編號(hào)(4)姓名(8)性別電話(11)地址(31)\n");printf("--------------------------------------------------------------------------------------\n");scanf("%s%s%s%s%s",p-data.num,p-data.name,p-data.sex,p-data.phone,p-data.addr);rear-next=p;//新結(jié)點(diǎn)連接到尾結(jié)點(diǎn)之后rear=p;//尾指針指向新結(jié)點(diǎn)printf("結(jié)束建表嗎?(1/0):");scanf("%d",flag);}rear-next=NULL;//終端結(jié)點(diǎn)指針置空returnhead;//返回鏈表頭指針}/******************************//*在通訊錄鏈表head中插入結(jié)點(diǎn)*//******************************/voidInsertNode(LinkListhead,ListNode*p){ListNode*p1,*p2;p1=head;p2=p1-next;while(p2!=NULLstrcmp(p2-data.num,p-data.num)next;//p2指向表的下一個(gè)結(jié)點(diǎn)}p1-next=p;//插入p所指向的結(jié)點(diǎn)p-next=p2;//連接表中剩余的結(jié)點(diǎn)}/******************************************//*有序通訊錄鏈表的查找*//******************************************/ListNode*ListFind(LinkListhead){//有序通訊錄鏈表上的查找ListNode*p;charnum[5];charname[9];intxz;printf("==================\n");printf("1.按編號(hào)查詢\n");printf("2.按姓名查詢\n");printf("==================\n");printf("請(qǐng)選擇:");p=head-next;//假定通訊錄表帶頭結(jié)點(diǎn)scanf("%d",xz);if(xz==1){printf("請(qǐng)輸入要查找者的編號(hào):");scanf("%s",num);while(pstrcmp(p-data.num,num)next;if((p==NULL)||strcmp(p-data.num,num))0;p=NULL;//沒(méi)有查到要查找的通訊者}elseif(xz==2){printf("請(qǐng)輸入要查找者的姓名:");scanf("%s",name);while(pstrcmp(p-data.name,name)!=0)p=p-next;}returnp;}/*******************************//*通訊錄鏈表上的結(jié)點(diǎn)刪除*//*********************************/voidDelNode(LinkListhead){charjx;ListNode*p,*q;p=ListFind(head);//調(diào)用查找函數(shù)if(p==NULL){printf("沒(méi)有查到要?jiǎng)h除的通訊者!\n");return;}printf("真的要?jiǎng)h除該結(jié)點(diǎn)嗎?(y/n):");scanf("%c",jx);if(jx=='y'||jx=='Y'){q=head;while((q!=NULL)(q-next!=p))q=q-next;q-next=p-next;//刪除結(jié)點(diǎn)free(p);//釋放被刪結(jié)點(diǎn)空間printf("通訊者已被刪除!\n");}}/**********************************//*通訊錄鏈表的輸出函數(shù)*//**********************************/voidprintList(LinkListhead){ListNode*p;p=head-next;printf("編號(hào)姓名性別聯(lián)系電話地址\n");printf("--------------------------------------------------------------------------------\n");while(p!=NULL){printf("%s,%s,%s,%s,%s\n",p-data.num,p-data.name,p-data.sex,p-data.phone,p-data.addr);printf("---------------------------------------------------------------------------------\n");p=p-next;//后移一個(gè)結(jié)點(diǎn)}}
"gotoxy()","moveto()"包含在#include conio.h中了.
轉(zhuǎn)載一個(gè)程序給你:(ZT)
算法:將當(dāng)前時(shí)間顯示到屏幕,當(dāng)時(shí)間發(fā)生變化時(shí),清屏,顯示新的時(shí)間(當(dāng)有鍵盤(pán)操作時(shí)退出程序)。
顯示時(shí)間格式:小時(shí):分鐘:秒
/* 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;
}