I have a program that asks to input two arguments using argv and I would like to then using the length of argv[1] and argv[2] dynamically allocate memory for two pointers to char inside my struct equal to the size of argv[1] and argv[2].
Here is my code but I'm not sure if I did it correctly, can anyone verify? Parameters passedargv1 and passedargv2 inside the function are argv[1] and argv[2] passed from the main() function. Basically I want to make chararray1=argv[1] and chararray2=argv[2] as if they were just plain char arrays, but I don't know ahead of time the size of our input so I can't pre-initialize chararray2 and chararray2. Also, I can't change what is inside argv, so i cannot have chararray1 and chararray2 just point to them because I will need to change them later on.
struct StructInformation{
char *chararray1;
char *chararray2;
};
typedef struct StructInformation SimplifiedStruct;
SimplifiedStruct *CreateMem(char *passedargv1, char *passedargv2) {
SimplifiedStruct *ptr=(SimplifiedStruct*)malloc(sizeof(SimplifiedStruct));
ptr->chararray1=(char*)malloc(sizeof(passedargv1));
ptr->chararray2=(char*)malloc(sizeof(passedargv2));
strdup()and stop castingmalloc()results