Let me preface with my c
background is about as deep as a puddle in the desert.
I'm trying to create a struct
that has this format:
struct Event {
char time[20];
char name[20];
char userId[20];
};
Then assign the values like this:
int main(int argc, const char * argv[]) {
struct Event event1;
strcpy( event1.time, "2007-03-01T13:00:00Z");
strcpy( event1.name, "VS");
strcpy( event1.userId, "2d97f036a1T13G21Jm0Z");
printf("%s", event1.time);
return 0;
}
However, I'm getting SIGABRT
on this line:
strcpy( event1.time, "2007-03-01T13:00:00Z");
Which makes sense because of the number values in the timestamp. I can't seem to find anything on how to store both numbers and characters in string.
char time[20]
: not enough bytes to hold a 20-byte string. You forgot the trailing zero.\0
character also needs one place. So, I think changingchar time[20]
tochar time[21]
can solve the problem.#include <string.h>
forstrcpy()