#include<stdio.h>
typedef struct{
unsigned short area;
unsigned short exchange;
unsigned short station;
}Number;
typedef struct{
unsigned char year;
unsigned char month;
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char second;
}Time;
typedef struct{
Time time;
Number number_calling;
Number number_called;
Number number_billed;
}Addresslist;
void timeinput(Addresslist *addresslist);
void numberinput(Addresslist *addresslist);
int main(){
Addresslist addresslist={0};
timeinput(&addresslist);
numberinput(&addresslist);
printf("The addresslist:\nYear:%d%d Month:%d Day:%d\nCallingNumber:%d-%d-%d\nCalledNumber:%d-%d-%d\nBilledNumber:%d-%d-%d\n",
addresslist.time.year>99?2:20,addresslist.time.year,addresslist.time.month,addresslist.time.day,
addresslist.number_calling.area,addresslist.number_calling.exchange,addresslist.number_calling.station,
addresslist.number_called.area,addresslist.number_called.exchange,addresslist.number_called.station,
addresslist.number_billed.area,addresslist.number_billed.exchange,addresslist.number_billed.station);
return 0;}
//
void timeinput(Addresslist *addresslist){
unsigned int ch=0,temp_year=0,temp_month=0,temp_day=0;
for(fputs("Input the year,month,day,divided with space:->",stdout);
(ch=scanf_s("%u %u %u",&temp_year,&temp_month,&temp_day))!=3||temp_year>2256||temp_year<2000||temp_month>12||temp_day>31;
fputs("Input the year month day,divided with space:->",stdout));
while((ch=getchar())!=EOF&&ch!=10);
temp_year%=1000;
addresslist->time.year=temp_year,addresslist->time.month=temp_month,addresslist->time.day=temp_day;
}
void numberinput(Addresslist *addresslist){
unsigned int ch=0,temp_area=0,temp_exchange=0,temp_station=0;
for(fputs("Input the area,exchange,station of calling number,divides with space:->",stdout);
(ch=scanf_s("%u %u %u",&temp_area,&temp_exchange,&temp_station))!=3;
fputs("Input the area,exchange,station of calling number,divides with space:->",stdout));
while((ch=getchar())!=EOF&&ch!=10);
addresslist->number_calling.area=temp_area;
addresslist->number_calling.exchange=temp_exchange;
addresslist->number_calling.station=temp_station;
for(fputs("Input the area,exchange,station of called number,divides with space:->",stdout);
(ch=scanf_s("%u %u %u",&temp_area,&temp_exchange,&temp_station))!=3;
fputs("Input the area,exchange,station of called number,divides with space:->",stdout));
while((ch=getchar())!=EOF&&ch!=10);
addresslist->number_called.area=temp_area;
addresslist->number_called.exchange=temp_exchange;
addresslist->number_called.station=temp_station;
for(fputs("Input the area,exchange,station of billed number,divides with space:->",stdout);
(ch=scanf_s("%u %u %u",&temp_area,&temp_exchange,&temp_station))!=3;
fputs("Input the area,exchange,station of billed number,divides with space:->",stdout));
while((ch=getchar())!=EOF&&ch!=10);
addresslist->number_billed.area=temp_area;
addresslist->number_billed.exchange=temp_exchange;
addresslist->number_billed.station=temp_station;
}
10.11.1-PointersOnC-20220308
最新推荐文章于 2024-10-01 20:11:33 发布