Well, basically what I need to do is take a command line argument and store its value in a char * located in a struct.
When i compile I get no errors concerning the sprintf line, but when I run the program with a simple string as an argument it gets a Segmentation Fault at the above highlighted sprintf line. The member orig is a char pointer inside the struct. Any help on getting that argument printed into the memory pointed to by dir would be greatly appreciated.Code:int main(int argc, char *argv[]) { // some other stuff struct dir_path *dir = malloc(sizeof(struct dir_path)); if (argc != 2) { printf("USAGE: ./backup <dir name>\n"); exit(EXIT_FAILURE); } //some stuff sprintf(dir->orig, "%s", argv[1]); //other stuff }
EDIT: Do I need to allocate memory for the struct members as well as the whole struct?
Thanks