求大神帮我改改程序,谢谢了。
#include<stdio.h>
#include<string.h>
#define N 5
struct add27xbb
{
char name[10];
char tel1[20];
char tel2[20];
char addr[15];
char email[30];
};
struct add27xbb people[N]={
{"Jack","13800000000","13800000001","shanghai","Jack@},
{"Mary","13900000000","13900000001","unknow","Mary@},
{"John","15100000000","05168320000","beijing","John@},
{"Smith","15200000000","unknow","unknow"," Rose#},
{"Rose","15600000000","152000000002","xzit","unknow"}
};
main()
{
char tel[20];
char tel3[20];
printf("输入你要查找的电话号码 :\n");
gets(tel);
printf("输入你要修改的电话号码:\n");
gets(tel3);
int flag=0;
for(int i=0;i<N;i++)
{
if(strcmp(people[i].tel1,tel)==0)
{
printf("%s%15s%15s%15s%15s\n","姓名","电话1","电话2","住址","邮箱");
printf("%s%15s%15s%15s%18s\n",people[i].name,people[i].tel1,people[i].tel2,people[i].addr,people[i].email);
strcpy(people[i].tel1,tel3);
puts("修改后的信息是:\n");
printf("%s%15s%15s%15s%18s\n",people[i].name,people[i].tel1,people[i].tel2,people[i].addr,people[i].email);
flag=1;
}
if(strcmp(people[i].tel2,tel)==0)
{
printf("%s%15s%15s%15s%15s\n","姓名","电话1","电话2","住址","邮箱");
printf("%s%15s%15s%15s%18s\n",people[i].name,people[i].tel1,people[i].tel2,people[i].addr,people[i].email);
strcpy(people[i].tel2,tel3);
puts("修改后的信息是:\n");
printf("%s%15s%15s%15s%18s\n",people[i].name,people[i].tel1,people[i].tel2,people[i].addr,people[i].email);
flag=1;
}
}
if(flag==0)
puts("查找的电话有错,请核对后输入。");
}
这是我对第三题的解法,但是我觉得有两个问题,一是其中一个电话号码是十二位,输入正确的电话号码也不能改对(因为是复制函数),二是有的电话都是unknow,这怎么改?还是我理解错了根本就不用管它们?