How to write character to an array of pointers in C? [closed]

You need

  1. A separate index for writing to szBuffer

  2. 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);

Leave a Comment