You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
687 B
43 lines
687 B
void sort()
|
|
{
|
|
FILE *fp;
|
|
struct addritem t;
|
|
int i,j,count=0;
|
|
if((fp=fopen("data.txt","r+"))==NULL)
|
|
{
|
|
printf("can not open\n");
|
|
return;
|
|
}
|
|
while(!feof(fp))
|
|
if(fread(&addrinfo[count],LEN,1,fp)==1)
|
|
count++;
|
|
fclose(fp);
|
|
if(count==0)
|
|
{
|
|
printf("no record!\n");
|
|
return;
|
|
}
|
|
for(i=0;i<count-1;i++)
|
|
for(j=i+1;j<count;j++)
|
|
if(strcmp(addrinfo[i].name,addrinfo[j].name)>0)
|
|
{
|
|
t=addrinfo[i];
|
|
addrinfo[i]=addrinfo[j];
|
|
addrinfo[j]=t;
|
|
}
|
|
if((fp=fopen("data.txt","w"))==NULL)
|
|
{
|
|
printf("can not open\n");
|
|
return;
|
|
}
|
|
for(i=0;i<count;i++)
|
|
if(fwrite(&addrinfo[i],LEN,1,fp)!=1)
|
|
{
|
|
printf("can not save!\n");
|
|
getch();
|
|
}
|
|
fclose(fp);
|
|
printf("successfully!\n");
|
|
}
|
|
|