char* inputStr2 = strcpy(inputStr2, inputStr); % Not working and causing matlab to crash
This line crashes because inputStr2 is an unitialized pointer and you are attempting to copy data to whatever garbage value happens to be contained in inputStr2 as a memory location. You need to allocate memory behind inputStr2 (e.g. via mxMalloc or mxCalloc) before you can copy into where it points to. E.g., you need something like this:
#include <string.h> // include the header file that has strcpy !!!
:
char *inputStr2 = (char *)mxMalloc( some expression for the number of chars needed ); // I will let you figure this out
strcpy(inputStr2, inputStr);
This line doesn't crash because mxArrayToString has memory allocation functions built into the function:
char* inputStr = mxArrayToString(prhs[0]);
You also need to free the memory behind the pointers when you are done with them. E.g.,
mxFree(inputStr);
mxFree(inputStr2);
But this all begs the question, why do you need to copy the string into a new string at all? Why not just use inputStr directly downstream in your code?