题解 | 出生日期输入输出
#include <stdio.h> #include <string.h> char* substring(const char* source, char* destination, int start, int length) { strncpy(destination, source + start, length); destination[length] = '\0'; // 确保目标字符串以空字符结尾 return destination; } int main() { char day[8]; char year[4]; char month[2]; char date[2]; scanf("%s", day); printf("year=%s\n",substring(day,year,0,4)); printf("month=%s\n",substring(day,month,4,2)); printf("date=%s\n",substring(day,day,6,2)); return 0; }