}
n=p-q;
do
{
printf("请输入新纪录的学号:");
do
gets(tempnum);
while(strcmp(tempnum,"")==0);
printf("请输入新纪录的姓名:");
gets(tempname);
printf("请输入新纪录的电话:");
gets(temptel);
for(p=q;p-q<n;p++)
if(strcmp(tempnum,p->num)==0||strcmp(temptel,p->tel)==0)
{
printf("学号或电话号码需要重新输入吗(Y/N)?");
c=getche();
putchar('\n');
break;
}
if(p-q==n)
{
strcpy(p->num,tempnum);
strcpy(p->name,tempname);
strcpy(p->tel,temptel);
break;
}
}while(c=='y'||c=='Y');
fp=fopen("d:\\jilu.dat","w");
if(fp==NULL){printf("error"); return;}
for(p=q;p-q<=n;p++)
fprintf(fp,"%23s%15s%15s\n",p->num,p->name,p->tel);
fclose(fp);
M++;
}
void mydelete(struct student *p,int n)
{
FILE *fp=NULL;
struct student *q=p;
char c[10]="",tempnum[10]="",tempname[10]="",temptel[10]="",choose='\0';
mydisplay(p,n);
printf("选择删除记录的方式:学号(h)姓名(m)");
choose=getche();
printf("\n");
if(choose=='m'||choose=='M')
{
printf("删除的记录:");
gets(c);
for(;p-q<n;p++)
if(strcmp(c,p->name)==0) break;
if(p-q<n)
for(;p-q<n-1;p++)
{
strcpy(p->num,(p+1)->num);
strcpy(p->name,(p+1)->name);
strcpy(p->tel,(p+1)->tel);
}
else printf("no\n");
}
else if(choose=='h'||choose=='H')
{
printf("删除的记录:");
gets(c);
for(;p-q<n;p++)
if(strcmp(c,p->num)==0) break;
if(p-q<n)
for(;p-q<n-1;p++)
{
strcpy(p->num,(p+1)->num);
strcpy(p->name,(p+1)->name);
strcpy(p->tel,(p+1)->tel);
}
else printf("no");
}
else printf("wrong\n");
fp=fopen("d:\\jilu.dat","w");
if(fp==NULL){printf("error"); return;}
for(p=q;p-q<n-1;p++)
fprintf(fp,"%23s%15s%15s\n",p->num,p->name,p->tel);
fclose(fp);
M--;
}
void mysort(struct student *p,int n)
{
FILE *fp=NULL;
struct student *q=p,*w=p,*a=p;
char temp[10]="",c1='\0',c2='\0';
mydisplay(p,n);
printf("选择按照学号(h)或姓名(m)排序:\n");
c1=getche();
if(c1=='h'||c1=='H')
{
printf("升序(s)或者降序(j)排列:");
c2=getche();
if(c2=='s'||c2=='S')
for(;p-a<n;p++)
{
w=p;
for(q=p+1;q-a<n;q++)
if(strcmp(w->num,q->num)>0) w=q;
strcpy(temp,w->num);
strcpy(w->num,p->num);
strcpy(p->num,temp);
strcpy(temp,w->name);
strcpy(w->name,p->name);
strcpy(p->name,temp);
strcpy(temp,w->tel);
strcpy(w->tel,p->tel);
strcpy(p->tel,temp);
}
else if(c2=='j'||c2=='J')
for(;p-a<n;p++)
{
w=p;
for(q=p+1;q-a<n;q++)
if(strcmp(w->num,q->num)<0) w=q;
strcpy(temp,w->num);
strcpy(w->num,p->num);
strcpy(p->num,temp);
strcpy(temp,w->name);
strcpy(w->name,p->name);
strcpy(p->name,temp);
strcpy(temp,w->tel);
strcpy(w->tel,p->tel);
strcpy(p->tel,temp);
}
else printf("555wrong...\n");
}
else if(c1=='m'||c1=='M')
{
printf("升序(s)或者降序(j)排列:");
c2=getche();
if(c2=='s'||c2=='S')
for(;p-a<n;p++)
{
w=p;
for(q=p+1;q-a<n;q++)
if(strcmp(w->name,q->name)>0) w=q;
strcpy(temp,w->num);
strcpy(w->num,p->num);
strcpy(p->num,temp);
strcpy(temp,w->name);
strcpy(w->name,p->name);
strcpy(p->name,temp);
strcpy(temp,w->tel);
strcpy(w->tel,p->tel);
strcpy(p->tel,temp);
}
else if(c2=='j'||c2=='J')
for(;p-a<n;p++)
{
w=p;
for(q=p+1;q-a<n;q++)
if(strcmp(w->name,q->name)<0) w=q;
strcpy(temp,w->num);
strcpy(w->num,p->num);
strcpy(p->num,temp);
strcpy(temp,w->name);
strcpy(w->name,p->name);
strcpy(p->name,temp);
strcpy(temp,w->tel);
strcpy(w->tel,p->tel);
strcpy(p->tel,temp);
}
else printf("555wrong...\n");
}
else printf("555wrong...\n");
fp=fopen("d:\\jilu.dat","w");
if(fp==NULL){printf("error"); return;}
for(p=a;p-a<=n;p++)
fprintf(fp,"%23s%15s%15s\n",p->num,p->name,p->tel);
fclose(fp);
|