vc++6.0ͨѶ¼ϵͳ ÔËÐÐʱÎ޹ʽáÊø£¡£¡
³ÌÐò´úÂ룺
/*ͨѶ²¾*/ #include<stdio.h> struct person { char name[8]; char num[10]; char ege[5]; char sex[5]; char tel[15]; char addr[50]; }; char filename[20]; FILE *fp; void creat(); void output(); void search(); void append(); void modify(); void delete(); void main() { int m; creat(); while(1) { printf("\n\nÌí¼Ó£¬Çë°´1"); printf("\n²éÕÒ£¬Çë°´2"); printf("\nÐ޸ģ¬Çë°´3"); printf("\nɾ³ý£¬Çë°´4"); printf("\nÊä³ö£¬Çë°´5"); printf("\nÍ˳ö£¬Çë°´0\n"); scanf("%d",&m); if(m>=0&&m<=5) { switch(m) { case 1: append(); break; case 2: search(); break; case 3: modify(); break; case 4: delete(); break; case 5: output(); break; case 0: exit(); } printf("\n\n²Ù×÷Íê±Ï£¬ÇëÔÙ´ÎÑ¡Ôñ£¡"); } else printf("\n\nÑ¡Ôñ´íÎó£¬ÇëÔÙ´ÎÑ¡Ôñ£¡"); } } void creat() { struct person one; long s1; printf("\nÇëÊäÈëͨѶ²¾Ãû£º"); scanf("%s",filename); if((fp=fopen(filename,"w"))==NULL) { printf("\n²»Äܽ¨Á¢Í¨Ñ¶²¾£¡"); exit(); } fprintf(fp,"%-10s%-10s%-6s%-6s%-20s%-50s\n","ÐÕÃû","ѧºÅ","ÄêÁä","ÐÔ±ð","µç»°ºÅÂë","סַ"); printf("\nÇëÊäÈëÐÕÃû¡¢Ñ§ºÅ¡¢ÄêÁä¡¢ÐԱ𡢵绰ºÅÂ뼰סַ£¨ÒÔ0½áÊø£©\n"); scanf("%s",one.name); while(strcmp(one.name,"0")) { scanf("%s%s%s%s%s",one.num,one.ege,one.sex,one.tel,one.addr); fprintf(fp,"%-10s%-10s%-6s%-6s%-20s%-50s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); scanf("%s",one.name); } fclose(fp); system("pause"); } void output() { struct person one; if((fp=fopen(filename,"r"))==NULL) { printf("\n²»ÄÜ´ò¿ªÍ¨Ñ¶²¾£¡"); exit(); } printf("\n\n%20s\n","ͨ Ѷ ²¾"); while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); printf("%-10s%-10s%-6s%-6s%-20s%-50s",one.name,one.num,one.ege,one.sex,one.tel,one.addr); } fclose(fp); } void append() { struct person one; if((fp=fopen(filename,"a"))==NULL) { printf("\n²»ÄÜ´ò¿ªÍ¨Ñ¶²¾£¡"); exit(); } printf("\nÇëÊäÈëÌí¼ÓµÄÐÕÃû¡¢Ñ§ºÅ¡¢ÄêÁä¡¢ÐԱ𡢵绰ºÅÂ뼰סַ\n"); scanf("%s%s%s%s%s%s",one.name,one.num,one.ege,one.sex,one.tel,one.addr); fprintf(fp,"%-10s%-10s%-6s%-6s%-20s%-50s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); fclose(fp); } void search() { int k=0; char namekey[8]; struct person one; printf("\nÇëÊäÈëÐÕÃû:"); scanf("%s",namekey); if((fp=fopen(filename,"rb"))==NULL) { printf("\n²»ÄÜ´ò¿ªÍ¨Ñ¶²¾£¡"); exit(); } while(!feof(fp)) { fscanf(fp,"%s%s%s%s%s%s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); if(!strcmp(namekey,one.name)) { printf("\n\nÒѲ鵽£¬¼Ç¼Ϊ£º"); printf("\n%-10s%-10s%-6s%-6s%-20s%-50s",one.name,one.num,one.ege,one.sex,one.tel,one.addr); k=1; } } if(!k) printf("\n\n¶Ô²»Æð£¬Í¨Ñ¶²¾ÖÐûÓдËÈ˵ļǼ¡£"); fclose(fp); } void modify() { int m,k=0; long offset; char namekey[8]; struct person one; printf("\nÇëÊäÈëÐÕÃû:"); scanf("%s",namekey); if((fp=fopen(filename,"r+"))==NULL) { printf("\n²»ÄÜ´ò¿ªÍ¨Ñ¶²¾£¡"); exit(); } while(!feof(fp)) { offset=ftell(fp); fscanf(fp,"%s%s%s%s%s%s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); if(!strcmp(namekey,one.name)) { k=1; break; } } if(k) { printf("\nÒѲ鵽£¬¼Ç¼Ϊ£º"); printf("\n%-10s%-10s%-6s%-6s%-20s%-50s",one.name,one.num,one.ege,one.sex,one.tel,one.addr); printf("\nÇëÊäÈëÐÂÐÕÃû¡¢Ñ§ºÅ¡¢ÄêÁä¡¢ÐԱ𡢵绰ºÅÂ뼰סַ£º"); scanf("%s%s%s%s%s%s",one.name,one.num,one.ege,one.sex,one.tel,one.addr); fseek(fp,offset,SEEK_SET); printf("%ld",ftell(fp)); fprintf(fp,"%-10s%-10s%-6s%-6s%-20s%-50s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); } else printf("\n¶Ô²»Æð£¬Í¨Ñ¶²¾ÖÐûÓдËÈ˵ļǼ¡£"); fclose(fp); } void delete() { int m,k=0,flag; long offset1,offset2; char namekey[8], valid[4]; struct person one; printf("\nÇëÊäÈëÐÕÃû:"); scanf("%s",namekey); if((fp=fopen(filename,"r+"))==NULL) { printf("\n²»ÄÜ´ò¿ªÍ¨Ñ¶²¾£¡"); exit(); } while(!feof(fp)) { offset1=ftell(fp); fscanf(fp,"%s%s%s%s%s%s\n",one.name,one.num,one.ege,one.sex,one.tel,one.addr); if(!strcmp(namekey,one.name)) { k=1; break; } } if(k) { printf("\nÒѲ鵽£¬¼Ç¼Ϊ"); printf("\n%-10s%-10s%-6s%-6s%-20s%-50s",one.name,one.num,one.ege,one.sex,one.tel,one.addr); printf("\nȷʵҪɾ³ý,°´1£»²»É¾³ý£¬°´0£º"); scanf("%d",&m); if(m) { fseek(fp,offset1,SEEK_SET); fprintf(fp,"%-10s%-10s%-6s%-6s%-20s%-50s\n","","","","","",""); } } else printf("\n¶Ô²»Æð£¬Í¨Ñ¶²¾ÖÐûÓдËÈ˵ļǼ¡£"); fclose(fp); } ±àÒëûÎÊÌâ ÔËÐÐҲûÎÊÌâ ¾ÍÊÇÔÚÊäÈëµÚ¶þ¸öÁªÏµÈËʱ ´°¿ÚÎÞ¹ÊÏûʧ Çó¾È£¿£¿£¿