C语言编写一个通讯录管理系统的源代码如下:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
/*定义保存通迅录的信息*/
structfriends
{
charname[20]/*名字*/
charprovince[20]/*省份*/
charcity[20]/*所在城市*/
charnation[20]/*民族*/
charsex[2]/*性别M/F*/
intage/*年龄*/
}
扩展资料
1、在C++中应该使用inline内连函数替代宏调用,这样既可达到宏调用的目的,又避免了宏调用的弊端。
2、在C语言两个函数的名称不能相同,否则会导致编译错误。在C++中,函数名相同而参数不同的两个函数被解释为重载。
3、在大型程序中,使函数名易于管理和使用,不必绞尽脑汁地去处理函数名。
分类: 电脑/网络 >>程序设计 >>其他编程语言解析:
"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+2p1.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(i<13i++)
{
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(i<13i++)
{
gotoxy(p.x+1, p.y+i)
printf("%5s%c"," ",2)
}
return 0
}
int print2(Point p)
{
int i=0
for(i<13i++)
{
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(i>0&&i<6)
printf("%5s%c"," ",2)
else
printf("%c",2)
}
return 0
}
int print3(Point p)
{
int i=0
for(i<13i++)
{
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(i<13i++)
{
gotoxy(p.x+1, p.y+i)
if(i<6) 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(i<13i++)
{
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(i>0&&i<6)
printf("%c",2)
else
printf("%5s%c"," ",2)
}
return 0
}
int print6(Point p)
{
int i=0
for(i<13i++)
{
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(i>0&&i<6)
printf("%c",2)
else
printf("%c%4s%c",2," ",2)
}
return 0
}
int print7(Point p)
{
int i=0
for(i<13i++)
{
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(i<13i++)
{
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(i<13i++)
{
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(i>0&&i<6)
printf("%c%4s%c",2," ",2)
else
printf("%5s%c"," ",2)
}
return 0
}
int clear(Point p)
{
int i=0
for(i<13i++)
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
}
参考文献:FROM do熊
#include&ltstdio.h&gt
#include&ltstdlib.h&gt
#include&ltstring.h&gt
#defineF-1
#defineT1
structAddress
{
charname[20]
charnumber[12]
charaddress[20]
structAddress*next
}
typedefstructAddress*node
intinit(node*head)
intcreat_tail(nodehead)
intinsert_index(nodehead)
intlength(nodehead)
intquery_name(nodehead)
intdelete_address(nodehead)
voidprint(nodehead)
intmain()
{
nodehead
init(&head)
intx
do
{
printf("0:exit\n")
printf("1:creat_tail\n")
printf("2:insert_index\n")
printf("3:query_name\n")
printf("4:delete_address\n")
printf("5:print\n")
printf("pleaseselect\n")
scanf("%d",&x)
switch(x)
{
case0:
exit(0)
case1:
creat_tail(head)
break
case2:
insert_index(head)
break
case3:
query_name(head)
break
case4:
delete_address(head)
break
case5:
print(head)
break
default:
exit(0)
}
}
while(1)
return0
}
intdelete_address(nodehead)
{
charaddress[20]
printf("pleaseinputtheaddressyouwanttodelete\n")
scanf("%s",address)
while(head-&gtnext!=NULL)
{
if(strcmp(head-&gtnext-&gtaddress,address)==0)
{
nodetemp=head-&gtnext
head-&gtnext=head-&gtnext-&gtnext
free(temp)
}
else
{
head=head-&gtnext
}
}
returnT
}
intquery_name(nodehead)
{
charname[20]
intcount=0,index=0
printf("pleaseinputthenameyouwant\n")
scanf("%s",name)
while(head-&gtnext!=NULL)
{
if(strcmp(head-&gtnext-&gtname,name)==0)
{
count++
printf("%d.name:%snumber:%saddress:%s\n",index+1,head-&gtnext-&gtname,head-&gtnext-&gtnumber,head-&gtnext-&gtaddress)
}
head=head-&gtnext
index++
}
if(count==0)
{
printf("notfound\n")
}
returnT
}
intlength(nodehead)
{
intcount=0
while(head-&gtnext!=NULL)
{
head=head-&gtnext
count++
}
returncount
}
intinsert_index(nodehead)
{
intindex
printf("pleaseinputtheindexyouwanttoadd\n")
scanf("%d",&index)
if(index&lt0||index&gt=length(head))
{
printf("outofrange\n")
returnF
}
nodenewnode=(node)malloc(sizeof(structAddress))
if(NULL==newnode)
{
returnF
}
inti
for(i=0i&ltindexi++)
{
head=head-&gtnext
}
printf("pleaseinputthename,number,address\n")
printf("whenyouinput000,exit\n")
scanf("%s%s%s",newnode-&gtname,newnode-&gtnumber,newnode-&gtaddress)
if(strcmp(newnode-&gtname,"0")!=0)
{
newnode-&gtnext=head-&gtnext
head-&gtnext=newnode
}
returnT
}
voidprint(nodehead)
{
intcount=0
while(head-&gtnext!=NULL)
{
count++
printf("%d.name:%snumber:%saddress:%s\n",count,head-&gtnext-&gtname,head-&gtnext-&gtnumber,head-&gtnext-&gtaddress)
head=head-&gtnext
}
}
intcreat_tail(nodehead)
{
do
{
nodenewnode=(node)malloc(sizeof(structAddress))
if(NULL==newnode)
{
returnF
}
printf("pleaseinputthename,number,address\n")
printf("whenyouinput000,exit\n")
scanf("%s%s%s",newnode-&gtname,newnode-&gtnumber,newnode-&gtaddress)
if(strcmp(newnode-&gtname,"0")!=0)
{
newnode-&gtnext=NULL
while(head-&gtnext!=NULL)
{
head=head-&gtnext
}
head-&gtnext=newnode
}
else
{
break
}
}
while(1)
returnT
}
intinit(node*head)
{
nodenewnode=(node)malloc(sizeof(structAddress))
if(NULL==newnode)
{
returnF
}
strcpy(newnode-&gtname,"0")
strcpy(newnode-&gtnumber,"0")
strcpy(newnode-&gtaddress,"0")
newnode-&gtnext=NULL
(*head)=newnode
returnT
}