Issue
I use in my current project a structure: for time information
struct SFileDateTime
{
uint8 nYear; // Years since 1900
uint8 nMonth; // Month [1, 12]
uint8 nDay; // Day of month [1, 31]
uint8 nHour; // Hours [0, 23]
uint8 nMinute; // Minutes [0, 59]
uint8 nSecond; // Seconds [0, 59]
};
typedef unsigned char uint8;
In some situations I get from external calls just a date char array
char [17] "1998012609260000"
I have now the problem to bring the char array to the SFileDateTime structure. I tried a memcpy call but this will cause a crash.
I currently do not understand why memcpy will not work. Is there any other way to convert it? Is casting the right choice?
Solution
U have 2 great answers in comments below your question. Hope this helps you a bit.
typedef unsigned char uint8; //Max size is 255 in decimal ( 1111 1111 )
struct SFileDateTime
{
uint8 nYear; // Years since 1900
uint8 nMonth; // Month [1, 12]
uint8 nDay; // Day of month [1, 31]
uint8 nHour[20]; // Hours [0, 23]
uint8 nMinute[]; // Minutes [0, 59]
uint8 nSecond; // Seconds [0, 59]
};
int main()
{
SFileDateTime nene;
nene.nYear = 33; // ASCII code for !
nene.nMonth = 'M'; // One char which is 77 in ASCII
nene.nDay = 255; // max number in ASCII which is space
nene.nSecond = 256 ; // No go||=== warning: large integer
//implicitly truncated to unsigned type [-Woverflow]|
char one[] = "Hello";
cout<<one<<endl;
nene.nHour[0] = 'A';
nene.nHour[1] = 'b';
nene.nHour[2] = 'b';
nene.nHour[3] = 'y';
return 0;
}
if u want to use strcpy use typedef char
U should convert it to single chars if you want to use your struct.
Here you can find a good reference : https://en.cppreference.com/w/c/chrono/localtime
Answered By - Dressy Fiddle