• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 315
  • Last Modified:

use of the function " system(" ") "

The first part of a C-program consists of copying the file "code.exe" to the existing folder "File menu".
I have tried :

system("XCOPY C:\code.exe C:\Fileme~1");

This does not work.Can anyone help me?
0
Naderassen
Asked:
Naderassen
2 Solutions
 
stefan73Commented:
Hi Naderassen,
You should escape backslashes:

system("XCOPY C:\\code.exe C:\\Fileme~1");


Cheers,
Stefan
0
 
Sys_ProgCommented:
Just to add to what Stefan said

A backslash character i.e. '\' is treated as an escape character in C/ C++
An escape character turns off the normal meaning of the immediately following character.

Thus, \n is treated/interpreted as a newline by C/C++ compilers

When u use
system("XCOPY C:\code.exe C:\Fileme~1");

the compiler assumes \c and \F to be an escape sequence AND not as a directory separator

Thus, as Stefann suggested, u would have to use a double '\' to turn off the normal meaning of '\' i.e. act as an escape character

Amit


0
 
stefan73Commented:
Most more modern windows system calls nowadays also support slashes instead of backslashes in file names. Sensible thing.

Those old commands from DOS times, however, use the slashes for options, so they can't handle them in file names. Stupid thing.

Stefan
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
rstaveleyCommented:
I wonder what the overall impact on the global economy has been made by the decision to make the default switch character '/' in DOS. Was that something DOS inherited from CPM?
0
 
stefan73Commented:
rstaveley,
Looks like CP/M is even more primitive:

http://home.tiscali.se/pausch/apple2/CPM.ref.txt

Stefan
0
 
rstaveleyCommented:
Directories were introduced in MS-DOS 2.0, so I guess that's when the bright idea about using the '\' came about. I now see from http://www.seasip.demon.co.uk/Cpm/optchar.html that the '/' "switch" character wasn't specifically the option lead-in character in CP/M, but it does date back to those days. If only those guys could have realised the impact of their arbitrary choices.
0
 
ankuratvbCommented:
Adding to Stefan's comment,

to see the result,u'll have to execute the executable if ur working in DOS.
Just Running the cpp file wont do.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now