This is the output i get when i try to compile your code using gcc:
In function 'SpacePlug':
8:33: warning: multi-character character constant [-Wmultichar]
*(StringPtr + i ) = '^^';
^
8:33: warning: overflow in implicit constant conversion [-Woverflow]
In function 'main':
17:17: error: expected expression before ')' token
SpacePlug(a,);
you should hace included the error report in the question, so it's easier to see what's going on.
You've got a few problems on your code:
"^^" is not a character, but a string with 2 characters. '^' is a character. That's the reason for the "multi-charater" error
You're not using "Ch" inside SpacePlug. The replacing character is hardcoded. I'ts always '^^', which doesn't exist.
The function is not properly called in main. It's missing a parameter.
Now for the solution. What i understood is that "SpacePlug" tries to find all spaces inside a string, the first parameter, and replace them with a character, which is the second parameter. The following code will work just fine for that:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void SpacePlug(char *StringPtr, char Ch, char *newString)
{
for (int i = 0; i < strlen(StringPtr); i++)
{
if (StringPtr[i] == ' ')
{
newString[i] = Ch;
}
else
{
newString[i] = StringPtr[i];
}
}
}
int main()
{
char *a = "Alton Tait";
char replace = '^';
char *newString = (char *)malloc(strlen(a) + 1); // the +1 is for the null terminator
SpacePlug(a, replace, newString);
printf("%s\n", newString);
free(newString);
}
Cheers.