I have a date string in format YYYYMMDDHH that I am trying to split into year YYYY month MM day DD, and hour HH.
Below is my code in which I am attempting to do this:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
char datetime[10];
char year;
char month;
char day;
char hour;
sprintf(datetime,"2022092300");
sscanf(datetime,"%4s%2s%2s%2s",year,month,day,hour);
printf("year is %s month is %s\n",year,month);
}
Unfortunately this code is not giving me a value for year and month and I doubt it would for day and hour. How do I tweak this code to get the desired results parsing the string into YYYYMMDDHH into YYYY, MM, DD, HH?