Вы, вероятно, хотите это:
#include <stdio.h>
int main()
{
char date[11];
char days[] = "DD";
char month[] = "MM";
char year[] = "YYYY";
printf("Enter the year that you want \n");
scanf("%10s", date); // limit input to 10 chars to prevent buffer overflow
days[0] = date[0];
days[1] = date[1];
month[0] = date[2];
month[1] = date[3];
year[0] = date[4];
year[1] = date[5];
year[2] = date[6];
year[3] = date[7];
printf("Today the day is %s, the month is %s and the year is %s", days, month, year);
return 0;
}
или даже проще:
#include <stdio.h>
#include <string.h>
int main()
{
char date[11];
char days[] = "DD";
char month[] = "MM";
char year[] = "YYYY";
printf("Enter the year that you want \n");
scanf("%10s", date);
memcpy(days, date + 0, 2);
memcpy(month, date + 2, 2);
memcpy(year, date + 4, 4);
printf("Today the day is %s, the month is %s and the year is %s", days, month, year);
return 0;
}
Пример:
Введите год, который вы хотите
01022019
Сегодня день 01, месяц 02, а год 2019
Но имейте в виду, что это очень неудобно, потому что вы вообще не проверяете,ввод правдоподобен, попробуйте ввести abcdefg
вместо 01022019
и посмотреть, что произойдет.