I am writing a simple function which removes non numeric characters in a string. Here I use a char pointer by allocating memory to it. However, when I try to free the allocated memory, the program fails at runtime . Kindly let me know why this is happening.
Also please let me know if there is a better way to achieve the above functionality.
char * FilterNumerics(char * Input, int iLength)
temp = (char *)malloc(iLength + 2);
printf("Memory Allocation Failed\n");
for (i = 0; i < iLength; i++)
if (Input[i] >= '0' && Input[i] <= '9')
temp[j] = Input[i];