You need
-
A separate index for writing to
szBuffer
-
Code that adds a zero termination to
szBuffer
Like:
int j = 0; // Index for storing in szBuffer
for (int i = 0; i < StrLenght - 1; i++) {
if (szPattern[i] == '%') {
// DO stuff....
} else {
szBuffer[j] = szPattern[i]; // Assign using index j
++j; // Increment index
}
}
szBuffer[j] = '\0'; // Zero terminate
puts(szBuffer);
2
solved How to write character to an array of pointers in C? [closed]