<p>So I've got some C code:</p>

<pre><code>#include &lt;stdio.h&gt;
#include &lt;string.h&gt;

/* putting one of the "char*"s here causes a segfault */
void main() {
  char* path = "/temp";
  char* temp;
  strcpy(temp, path);
}
</code></pre>

<p>This compiles, runs, and behaves as it looks. However, if one or both of the character pointers is declared as global variable, strcpy results in a segmentation fault. Why does this happen? Evidently there's an error in my understanding of scope.</p>

You forgot to allocate and initialize temp:
```
```
temp = (char *)malloc(TEMP_SIZE);
```
```
Just make sure TEMP_SIZE is big enough. You can also calculate this at run-time, then make sure the size is enough (should be at least strlen(path))