I have a string which is a date and comes in the format yyyymmdd. I need to find out the day,month, year and store them in separate strings and use them further. I have written the following code
char *date="20151221";
char day[2];
char month[2];
char year[4];
sprintf(day, "%c%c", date[6], date[7]);
sprintf(month, "%c%c", date[4], date[5]);
sprintf(year, "%c%c%c%c", date[0], date[1],date[2],date[3]);
lr_output_message("day is %s",day);
lr_output_message("month is %s",month);
lr_output_message("year is %s",year);
But the output am getting is
day is 21122015
month is 122015
year is 2015
Maybe its a dumb question,but I am new to C. Can anybody please explain the reason for this?