📄 latest.c
字号:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define sumno 10
int face();
void writes();
void reads();
void sorts();
void searches();
struct test
{
char name[20];
char No[15];
}s[sumno];
FILE * fp;
int m;
int main()
{
face();
return 0;
}
//////////////////////////////////////////////////////////////////////////////////
int face()
{
int rev;
printf("\n\n\n\n\n\n\n");
printf("\t\t ********************Welcome");
printf("********************\n");
printf(" *******************PhoneBook");
printf("*******************\n");
printf("\t\t 1.Add anumbers \n");
printf("\t\t 2.Read the numbers \n");
printf("\t\t 3.sorts \n");
printf("\t\t 4.searches \n");
printf("\t\t 5.qiut \n");
printf("\t\t Please Select(1-5): ");
scanf("%d",&rev);
switch(rev)
{
case 1:
writes();
break;
case 2:
reads();
break;
case 3:
sorts();
break;
case 4:
searches();
break;
case 5:
return 0;
}
return 0;
}
/////////////////////////////////////////////////////////////////////////////////
void writes()
{
int n;
printf("How many do you want to insert(0<m<11):");
scanf("%d",&m);
for(n=0;n<m;n++)
{
printf("Insert the Name:");
scanf("%s",&s[n].name);
printf("Insert the No:");
scanf("%s",&s[n].No);
}
fp = fopen("file1","a+");
fwrite(s,sizeof(struct test),m,fp);
fclose(fp);
printf("Add successfully!\n");
face();
}
////////////////////////////////////////////////////////////////////////////////
void reads()
{
int i;
fp = fopen("file1","r");
fread(s,sizeof(struct test),sumno,fp);
fclose(fp);
printf("The content:\n");
for(i=0;i<sumno;i++)
printf("%-20s %s\n",s[i].name,s[i].No);
face();
}
////////////////////////////////////////////////////////////////////////////////
void sorts()
{
int i,j,k;
char string[20];
char strno[15];
fp = fopen("file1","r");
fread(s,sizeof(struct test),sumno,fp);
fclose(fp);
for(j=0;j<sumno;j++)
for(k=0;k<sumno-j;k++)
if(strcmp(s[k].name,s[k+1].name) <0)
{
strcpy(string,s[k].name);
strcpy(strno,s[k].No);
strcpy(s[k].name,s[k+1].name);
strcpy(s[k].No,s[k+1].No);
strcpy(s[k+1].name,string);
strcpy(s[k+1].No,strno);
}
printf("The new order:\n");
for(i=0;i<sumno;i++)
printf("%-20s %s\n",s[i].name,s[i].No);
face();
}
/////////////////////////////////////////////////////////////////////////////////
void searches()
{
char name[20];
int i;
printf("Whose number do you wanna find:");
scanf("%s",&name);
fp = fopen("file1","r");
fread(s,sizeof(struct test),sumno,fp);
fclose(fp);
for(i=0;i<sumno;i++)
{
if(strcmp(s[i].name,name)==0)
{
printf("The one you wanna find is:\n");
printf("%-20s %s\n",s[i].name,s[i].No);
}
else
{
printf("The people you find is not in the phoonbook!");
}
}
face();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -