I have the following char pointer string "Friday 6 June 11:08:04 2020" and I would like to split it into the following:
date = Friday 6 June
time = 11:08:04
The code I am trying to implement is below:
#include <stdio.h>
#include <string.h>
int main()
{
char *message = "Friday 6 June 11:08:04 2020";
char time_buff[9] = {0};
char date_buff[13] = {0};
for(int d=0; d<13; d++){
date_buff[d] = message[d];
}
for(int t=14; t<23; t++){
time_buff[t] = message[t];
}
for(int p=0; p<13; p++){
printf("%c ", date_buff[p]);
}
return 0;
}
When I run this code I get the following error:
*** stack smashing detected ***: terminated
Aborted (core dumped)
How can I fix this problem and split the string into date and time parts?