ͨѶ¼.exeÍ£Ö¹¹¤×÷ÊÇʲôÎÊÌâ°¡
cÓïÑÔµ÷ÊÔʱ³öÏÖÕâÖÖÇé¿öÊÇʲôÎÊÌâ°¡ ÇëÎÊ#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<windows.h>
#define True 1
int i;
//º¯ÊýÉùÃ÷
struct person*read();//´ÓÎļþÖжÁÈ¡¸öÈËÐÅÏ¢
void write(struct person*f); //ÏòÎļþÖÐдÈë¼Ç¼
void find(struct person*f); //²éѯÐÅÏ¢
void modify(struct person*f); //ÐÞ¸ÄÐÅÏ¢
struct person*add(struct person*f);//Ìí¼ÓÐÅÏ¢
struct person*del(struct person*f); //ɾ³ýÐÅÏ¢
void list(struct person*f); //ä¯ÀÀÐÅÏ¢
struct person //½¨Á¢¸öÈËÐÅÏ¢½á¹¹£¬²ÉÓõ¥ÏòÁ´±í
{
struct person*front; //´ÓÎļþÖжÁÈ¡ÊÇ·ñ»áÕ¾¸ü´ó¿Õ¼ä£¿
struct person*behind;//²âÕ¼Ëĸö×Ö½Ú
int number;//ÐòºÅ
char name[10];//ÐÕÃû
char* sex;//ÐÔ±ð
int telephone;//µç»°ºÅÂë
int QQ;
int homenumber;//¼ÒÍ¥µç»°
char* email;//µç×ÓÓʼþ
char address[30];//ͨѶµØÖ·
struct
{
unsigned short year;
unsigned short month;
unsigned short day;
}birthday; //³öÉúÈÕÆÚ
};
void main()
{
char*filename;
struct person*f;//ÉùÃ÷Ö¸Ïò½á¹¹ÌåµÄÖ¸Õë±äÁ¿£¬¼Ç¼Á´±íµÄÊ×µØÖ·
f=read();//´ÓÎļþÖжÁÈ¡ÐÅÏ¢£¬²¢³õʼ»¯½á¹¹ÌåÊý×é
while(True)
{
printf("\n\n\t\t**»¶ÓʹÓôËͨѶ¼¹ÜÀíϵͳ**\n\n\n");
printf("\t\tÇëÑ¡Ôñ£¨1-7£©:\n");
printf("\t\t***********************************\n");
printf("\t\t\t1.²éѯͨѶ¼ÐÅÏ¢\n");
printf("\t\t\t2.ÐÞ¸ÄͨѶ¼ÐÅÏ¢\n");
printf("\t\t\t3.Ìí¼ÓͨѶ¼ÐÅÏ¢\n");
printf("\t\t\t4.ɾ³ýͨѶ¼ÐÅÏ¢\n");
printf("\t\t\t5.±£´æÐÅÏ¢µ½Îļþ\n");
printf("\t\t\t6.ä¯ÀÀͨѶ¼ÐÅÏ¢\n");
printf("\t\t\t7.Í˳öϵͳ\n");
printf("\n\n\t\t*******************************\n");
printf("\n\t\tÄãµÄÑ¡ÔñÊÇ:");
scanf("%d",&i);
switch(i)
{
case 1:find(f);break;
case 2:modify(f);break;
case 3:f=add(f);break;
case 4:f=del(f);break;
case 5:write(f);break;
case 6:list(f);break;
case 7:return;
default:printf("\t\tÑ¡Ôñ´íÎó£¬ÇëÖØÐÂÑ¡Ôñ£¨1-7£©:\n");getchar();
}
}
return;
}
//´ÓÎļþ¡°filename¡±ÖжÁÈ¡ÐÅÏ¢µ½½á¹¹Êý×éÖÐ
struct person * read()
{
int i;
FILE*fp;
int n=0;
struct person*f,*readdata;//¼Ç¼Ê×µØÖ·¼°Ð·ÖÅäµØÖ·
struct person*p; //Öмä±äÁ¿
if((fp=fopen("filename","rb"))==NULL)
{
printf("\n\n\tÎļþÎÞ·¨´ò¿ª!");
printf("\n\n\t°´ÈÎÒâ¼ü½øÈëÖ÷²Ëµ¥¡¤¡¤¡¤¡¤¡¤¡¤");
scanf("%d",&i);
return 0;
}
else
{
//ÉêÇë·ÖÅäÄÚ´æ¿Õ¼ä£¬²¢»ñµÃÄÚ´æ·ÖÅäÊ×µØÖ·
readdata=(struct person*)malloc(sizeof(struct person));
//Ñ»·¶ÁÈ¡ÎļþÐÅÏ¢µ½Ð·ÖÅäµÄÄÚ´æ¿Õ¼ä
while(fread(readdata,sizeof(struct person),1,fp)==1)
{
if(n==0) //˵Ã÷ÐèÒª½¨Á¢Á´±íÆðʼÏî
{
f=readdata;
f->front=NULL;
f->behind=NULL;
p=readdata;
}
else//˵Ã÷×·¼ÓÁ´±íÊý¾ÝÏî
{
p->behind=readdata;
readdata->front=p;
readdata->behind=NULL;
p=readdata;
}
n++;
readdata=(struct person*)malloc(sizeof(struct person));
}
fclose(fp);
printf("\n\nͨѶ¼ÐÅÏ¢¶ÁÈ¡Íê±Ï£¬¹²ÓÐ%dÈË£¡\n",n);
}
printf("\n°´ÈÎÒâ¼ü½øÈë²Ëµ¥¡¤¡¤¡¤¡¤");
return f;
}
//ÏòͨѶ¼ÎļþдÈë¼Ç¼
void write(struct person*f)
{FILE*fp;//ÉùÃ÷ÎļþÖ¸Õë
int n=0;//ͳ¼Æ´æÈëͨѶ¼ÈËÊý
if(f==NULL)//ÄÚ´æÖÐÎÞÐÅÏ¢¼Ç¼
{
printf("ûÓÐÐÅÏ¢¿É´æ£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤\n");
scanf("%d",&i);
return;
}
if((fp=fopen("filename","wb"))!=NULL)
{
do
{
fwrite(f,sizeof(struct person),1,fp);
n++;
f=f->behind;
}while(f!=NULL);
fclose(fp);
printf("\n\n\t\t%dÌõÐÅÏ¢¼Ç¼±£´æÍê±Ï£¡\n",n);
}
else
printf("\t\tÎÞ·¨´ò¿ªÍ¨Ñ¶Â¼Îļþ!n");
printf("\n\n\n\t°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
}
//²éѯͨѶ¼¸öÈËÐÅÏ¢£¨ÒÀ¾ÝÈËÃû£©
void find(struct person*f)
{
char name[10];
if(f==NULL)//˵Ã÷ÄÚ´æÎÞÐÅÏ¢
{
printf("µ±Ç°»¹Ã»ÓÐÐÅÏ¢£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤\n");
scanf("%d",&i);
return;
}
printf("\tÇëÊäÈëÐè²éѯÐÅÏ¢µÄÈËÃû:");
gets(name); //´Ó¼üÅ̶ÁÈ¡×Ö·û´®
while(f!=NULL)//´ÓÁ¬±í¿ªÊ¼Ïòºó²éÕÒ
{
if(strcmp(f->name,name)==0) //ÏÔʾ²¢ÕÒµ½
{ //ÏÔʾ¸ÃÈ˵ÄÐÅÏ¢
printf("\n\t\t\t%sµÄÐÅÏ¢ÈçÏ£º",name);
printf("\n\t\t\t*************************\n\n");
printf("% -3S%-9S%-3S%-9S%-9S%-9S%-9S%-9S%-9S","ÐòºÅ","ÐÕÃû","ÐÔ±ð","µç»°ºÅÂë","QQºÅÂë","¼ÒÍ¥ºÅÂë","µç×ÓÓʼþ","ͨѶµØÖ·","³öÉúÈÕÆÚ");
printf("%s%-6s%-3s",f->number,f->name,f->sex);
printf("&-9d%-9d%-9d",f->telephone,f->QQ,f->homenumber);
printf("%-9s%-9s",f->email,f->address);
printf("%d%d%d\n",f->birthday.year,f->birthday.month,f->birthday.day);
printf("\n°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return;
}
f=f->behind;
}
//Ñ»·×Ô¶¯½áÊøÒâζ×ÅδÕÒµ½
printf("\n\n\t\tÄúËùÊäÈëµÄÈËÃû²»´æÔÚ£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤\n");
scanf("%d",&i);
return;
}
//ä¯ÀÀͨѶ¼ÐÅÏ¢
void list(struct person*f)
{
printf("\n\n\t\t\tͨѶ¼ȫ²¿ÐÅÏ¢ÈçÏÂ:\n");
printf("\t\t\t*****8*********8***************\n\n");
if(f!=NULL)
{
do
{printf("% -3S%-9S%-3S%-9S%-9S%-9S%-9S%-9S%-9S","ÐòºÅ","ÐÕÃû","ÐÔ±ð","µç»°ºÅÂë","QQºÅÂë","¼ÒÍ¥ºÅÂë","µç×ÓÓʼþ","ͨѶµØÖ·","³öÉúÈÕÆÚ");
printf("%s%-6s%-3s",f->number,f->name,f->sex);
printf("&-9d%-9d%-9d",f->telephone,f->QQ,f->homenumber);
printf("%-9s%-9s",f->email,f->address);
printf("%d%d%d\n",f->birthday.year,f->birthday.month,f->birthday.day);
f=f->behind; //ÐÞÕýfÖ¸ÏòÁ´±íÖÐÏÂÒ»Ïî½á¹¹Êý¾Ý
} while(f!=NULL);
}
printf("°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return;
}
//ÐÞ¸ÄͨѶ¼ÐÅÏ¢
void modify(struct person*f)
{
char name[10];
if(f==NULL)
{printf("\n\n\t\tµ±Ç°»¹Ã»ÓдËÈËÐÅÏ¢¼Ç¼£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
getchar();
return;
}
printf("\tÇëÊäÈëÐÕÃû£º");
gets(name);
while(f!=NULL) //´ÓÁ´±í¿ªÊ¼ÏòºóÕÒ
{
if(strcmp(f->name,name)==0)
{
printf("\n\t\t\t´ËÈËÐÅÏ¢ÈçÏ£º");
printf("\n\t\t\t**************************************\n\n");
printf("% -3S%-9S%-3S%-9S%-9S%-9S%-9S%-9S%-9S","ÐòºÅ","ÐÕÃû","ÐÔ±ð","µç»°ºÅÂë","QQºÅÂë","¼ÒÍ¥ºÅÂë","µç×ÓÓʼþ","ͨѶµØÖ·","³öÉúÈÕÆÚ");
printf("%s%-6s%-3s",f->number,f->name,f->sex);
printf("&-9d%-9d%-9d",f->telephone,f->QQ,f->homenumber);
printf("%-9s%-9s",f->email,f->address);
printf("%d%d%d\n",f->birthday.year,f->birthday.month,f->birthday.day);
//½ÓÊÜ´ËÈËÐÂÐÅÏ¢
printf("\n\t\tÇëÊäÈë´ËÈËе绰ºÅÂ룺\n");
scanf("%d",&f->telephone);
printf("\t\tÇëÊäÈë´ËÈËÐÂQQºÅÂ룺\n");
scanf("%d",&f->QQ);
printf("\t\tÇëÊäÈë´ËÈËмÒÍ¥ºÅÂ룺\n");
scanf("%d"),&f->homenumber;
printf("\t\tÇëÊäÈë´ËÈËеç×ÓÓʼþ£º\n");
scanf("%s",&f->email);
printf("\t\tÇëÊäÈë´ËÈËÐÂͨѶµØÖ·£º\n");
scanf("%s",&f->address);
printf("\n\n\t\t´ËÈËÐÅÏ¢Ð޸ijɹ¦£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return;
}
f=f->behind;
}
printf("\n\n\t\tÄúËùÊäÈëµÄÈËÃûÓÐÎó»ò²»´æÔÚ£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
getchar();
return;
}
//ÏòͨѶ¼ÎļþÖÐÌí¼ÓÐÅÏ¢¼Ç¼
struct person*add(struct person*f)
{
struct person*adddata ;//¼Ç¼Ê×µØÖ·¼°Ð·ÖÅäÄÚ´æµØÖ·
struct person*p;//Öмä±äÁ¿
adddata=(struct person*)malloc(sizeof(struct person));
if(f==NULL) //Ðè´´½¨Á´±í
{
f=adddata;
f->front=NULL;
f->behind=NULL;
}
else //˵Ã÷ÐèÕÒµ½Á´±í½áÊøλÖÃ
{
p=f;
while(p->behind!=NULL)
{
p=p->behind;
}
//½¨Á¢Á´±í×·¼ÓÏîÖ¸ÕëÖ¸Ïò¹Øϵ
p->behind=adddata;
adddata->front=p;
adddata->behind=NULL;
}
//ÎÞÂÛÊÇ´´½¨µÚÒ»Ìõ»¹ÊÇ×·¼ÓÐÅÏ¢¼Ç¼£¬¾ùÖ»¶ÔadddataÌí¼ÓÐÅÏ¢
printf("\tÇëÊäÈëÐòºÅ£º");
fflush(stdin);
scanf("%d",adddata->number );
printf("\t\t\t\tÇëÊäÈëÐÕÃû£º");
gets(adddata->name);
printf("\n\t\t\t\tÇëÊäÈëÐÔ±ð£º");
gets(adddata->sex);
printf("\n\t\t\t\tÇëÊäÈëµç»°ºÅÂ룺");
scanf("%d",&adddata->telephone );
printf("\n\t\t\t\tÇëÊäÈëQQºÅÂ룺");
scanf("%d",&adddata->QQ );
printf("\n\t\t\t\tÇëÊäÈë¼ÒÍ¥µç»°£º");
scanf("%d",&adddata->homenumber );
printf("\n\t\t\t\tÇëÊäÈëµç×ÓÓʼþ£º");
gets(adddata->email);
printf("\n\t\t\t\tÇëÊäÈëͨѶµØÖ·£º");
gets(adddata->address);
printf("\n\n\t\t\t\tÌí¼Ó³É¹¦£¡°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return f;//·µ»Ø Á´±íÊ×µØÖ·
}
//´ÓͨѶ¼Îļþɾ³ýÐÅÏ¢¼Ç¼£¬Óõ½ÁËË«ÏòÁ´±í
struct person*del(struct person*f)
{
char name[10];
char d='N'; //½ÓÊÜÈ·ÈÏɾ³ý×Ö·û
struct person*p;//Öмä±äÁ¿
p=f;
if(p==NULL) //˵Ã÷ÎÞ¶ÔӦͨѶ¼ÐÅÏ¢
{
printf("\n\n\t\tµ±Ç°»¹Ã»ÓÐͨѶ¼ÐÅÏ¢£¬ÎÞ·¨Ö´ÐÐɾ³ý£¡");
printf("\n\n\t\t°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return f;
}
printf("\tÇëÊäÈë´ýɾ³ýÐÅÏ¢ÈËÔ±ÐÕÃû£º");
gets(name);
while(p!=NULL)
{
if(strcmp(p->name,name)==0)
{printf("\n\t\t\t*************************\n\n");
printf("% -3S%-9S%-3S%-9S%-9S%-9S%-9S%-9S%-9S","ÐòºÅ","ÐÕÃû","ÐÔ±ð","µç»°ºÅÂë","QQºÅÂë","¼ÒÍ¥ºÅÂë","µç×ÓÓʼþ","ͨѶµØÖ·","³öÉúÈÕÆÚ");
printf("%s%-6s%-3s",f->number,f->name,f->sex);
printf("&-9d%-9d%-9d",f->telephone,f->QQ,f->homenumber);
printf("%-9s%-9s",f->email,f->address);
printf("%d%d%d\n",f->birthday.year,f->birthday.month,f->birthday.day);
printf("\n\t\tÄãÈ·ÈÏҪɾ³ý%sµÄÐÅÏ¢Âð£¨y/n£©£¿",p->name);
d=getchar();
if(d=='y'||d=='Y') //È·ÈÏɾ³ý
{ //ÖØн¨Á¢Á´±í¹Øϵ
if(p->front==NULL&&p->behind==NULL)
//µ±Ö»ÓÐÒ»Ìõ¼Ç¼ʱ
{f=NULL;}
else if(p->front==NULL) //ɾ³ýµÄÊǵÚÒ»Ìõ¼Ç¼
{ f=p->behind;
f->front=NULL;
}
else if(p->behind==NULL) //ɾ³ýµÄÊÇ×îºóÒ»Ìõ¼Ç¼
{
(p->front)->behind=NULL;
}
else //ɾ³ý·ÇµÚÒ»Ìõ¼Ç¼
{ (p->front)->behind=p->behind;
(p->behind)->front=p->front;
}
free(p);//Êͷű»É¾³ýÐÅÏ¢ËùÕ¼ÄÚ´æ
printf("\n\n\t\t´ËÈËÐÅϢɾ³ý³É¹¦£¬°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return f;
}
else
{ printf("\n\n\t\tÄãÑ¡ÔñÁ˲»É¾³ý´ËÈËÐÅÏ¢£¬°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return f;
}
}
p=p->behind;//Ö¸ÏòÏÂÒ»Ïî½á¹¹
}
if(d=='n'||d=='N') //¸ÃÖµ·´Ó³Î´É¾³ý¼Ç¼µÄ״̬
{
printf("\n\t\t±¾Í¨Ñ¶Â¼ÎÞ´ËÈËÐÅÏ¢£¬°´ÈÎÒâ¼ü·µ»ØÖ÷²Ëµ¥¡¤¡¤¡¤");
scanf("%d",&i);
return f;
}
}
[ ±¾Ìû×îºóÓÉ cyuyan793445 ÓÚ 2013-3-3 11:30 ±à¼ ]