输入身份证,输出出生日期等信息

输入身份证号
输出出生日期,年龄,性别
例如:输入221023200110101315
输出2001年10月10日
年龄
性别

请你看这个帖子下面的 “相关推荐”, 你就可以找到答案了。

img

截取 第7位到 第14位 就是 年月日
参考如下:

#include <stdio.h>
#include <string.h>

int main(){
    char code[19] = "221023200110101315";
    char year[5], month[3], day[3];
    strncpy(year, code + 6, 4);
    year[4] = '\0';
    strncpy(month, code + 10, 2);
    month[2] = '\0';
    strncpy(day, code + 12, 2);
    day[2] = '\0';
    printf("%s年%s月%s日", year, month, day);
    return 0;
}