#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#define MAX_SIZE 18
#define uint unsigned int
typedef struct Date
{
int year;
int month;
int day;
int hour;
}Date;
Date get_time()
{
struct Date date = {0,0,0,0};
time_t current_time;
struct tm *timeinfo;
time(¤t_time); //get time
timeinfo = localtime(¤t_time); // to local time
printf("007 the current date/time is %s",asctime(timeinfo)); //asctime
date.year = timeinfo->tm_year+1900;
date.month = timeinfo->tm_mon+1;
date.day = timeinfo->tm_mday;
date.hour = timeinfo->tm_hour;
printf("current date is :%d-%d-%d\n",date.year,date.month,date.day);
return date;
}
int count(char *s)
{
if(NULL == s)
return -1;
int count= 0;
while(*s++)
{
count++ ;
}
return count;
}
int main()
{
char id[MAX_SIZE+1];
char age[9];
puts("intput your id card");
gets(id);
id[MAX_SIZE] = '\0';
int counter = count(id);
while(18 != counter)
{
puts("you input a incorrect num,input again\n");
gets(id);
}
printf("current id card num is:%s\n",id);
//get age from id card
memcpy(age,id+6,8*sizeof(char));
age[8] = '\0';
printf("you birthday is :%s\n",age);
int tmp_age = atoi(age);//to int
//get current time
Date tmp_date = get_time();
//calculate your age
printf("your age is :%d\n",tmp_date.year-tmp_age/10000);
char sex[2];
sex[0] = id[16];
sex[1] = '\0';
int sex_num = atoi(sex);
if(0 == sex_num%2)
{
printf("your are female\n");
}else
{
printf("your are male\n");
}
return 0;
}