I want to concatenate "/bin/" and "touch" so that I will have "/bin/touch".
In my program, I have
char* filePath = malloc((strlen("/bin/") + strlen(rv[0]))* sizeof(char));
filePath = strcat("/bin/",rv[0])
First of all, rv[0] contains a string, "touch". I allocate 10 bytes in memory by using malloc function, and filePath will be the pointer to those 10 bytes of memory. Because, the total length of the string concatenated ("/bin/touch") will be 10.
The program executes normally until the second line which gives me a segmentation fault. Did I make any mistake on the strcat function?