<p>I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000".</p>

<pre><code>char *StringPadRight(char *string, int padded_len, char *pad) {
    int len = (int) strlen(string);
    if (len &gt;= padded_len) {
        return string;
    }
    int i;
    for (i = 0; i &lt; padded_len - len; i++) {
        strcat(string, pad);
    }
    return string;
}
</code></pre>

<p>It works but has some weird side effects... some of the other variables get changed.  How can I fix this?</p>

The argument you passed "Hello" is on the constant data area. Unless you've allocated enough memory to char * string, it's overrunning to other variables.
```
```
char buffer[1024];
memset(buffer, 0, sizeof(buffer));
strncpy(buffer, "Hello", sizeof(buffer));
StringPadRight(buffer, 10, "0");
```
```
Edit: Corrected from stack to constant data area.