I'm getting a segmentation fault, and it seems to be happening because of wrong use of malloc. But why is this wrong?Code:f = fopen("test1.txt", "r"); if (f == NULL) { printf("Could not open file.\n"); exit(1); } //Memory allocation for output file name output_titles = (char*)malloc(sizeof(char*)*(strlen(strcat("test1.txt", ".titles"))+1)); //Creation of output file name strcpy(output_titles, strcat("test1.txt", ".titles"));