#include <stdio.h> #include <stdlib.h> #include <string.h> #include <uuid/uuid.h> void retrieveUuid(char *uuidValue); struct uuidStruct { int id; char *str; }; void array8(); int main() { array8(); return 0; } void retrieveUuid(char *uuidValue) { uuid_t newUUID; uuid_generate(newUUID); uuid_unparse(newUUID,uuidValue); } void array8() { struct uuidStruct arr[100]; char *str=(char*)malloc(40); struct uuidStruct us; for(int i=0;i<100;i++) { us.str=(char*)malloc(40); retrieveUuid(str); memcpy(us.str,str,strlen(str)); us.id=i*i*i*i; arr[i]=us; } for(int i=0;i<100;i++) { printf("Id=%d,str=%s\n",arr[i].id,arr[i].str); free(arr[i].str); } free(str); }
Must be allocated memory via malloc before the struct instance initialization