<p>In cmd.exe, I can execute the command "copy c:\hello.txt c:\hello2.txt" and it worked fine.
But in my C program, I ran this piece of code and got the following error:</p>

<pre><code>#include &lt;iostream&gt;

using namespace std;

int main()
{
    system("copy c:\hello.txt c:\hello2.txt");
    system("pause");

    return 0;
}
</code></pre>

<p>Output:
The system cannot find the file specified.</p>

<p>Anybody know what is going on here?</p>

Inside C strings (and quite a few other languages that use the same escaping rules),
```
\
```
should be
```
\\
```
since it's the escape character. It allows you to enter, in normal text, non-printable characters such as:
the tab character
```
\t
```
.
the carriage-return character
```
\r
```
.
the newline character
```
\n
```
.
others which I won't cover in detail.
Since
```
\
```
is used as the escape character, we need a way to put an
actual
```
'\'
```
into a string. This is done with the sequence
```
\\
```
.
Your line should therefore be:
```
```
system("copy c:\\hello.txt c:\\hello2.txt");
```
```
This can sometimes lead to obscure errors with commands like:
```
```
FILE *fh = fopen ("c:\text.dat", "w");
```
```
where the
```
\t
```
is actually the
```
tab
```
character and the file that you're trying to open is:
c
:
TAB
e
x
t
.
d
a
t
.