Solved

use of the function " system(" ") "

Posted on 2004-03-30
7
308 Views
Last Modified: 2010-04-15
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
Comment
Question by:Naderassen
7 Comments
 
LVL 12

Assisted Solution

by:stefan73
stefan73 earned 20 total points
ID: 10721669
Hi Naderassen,
You should escape backslashes:

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


Cheers,
Stefan
0
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 30 total points
ID: 10721865
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
 
LVL 12

Expert Comment

by:stefan73
ID: 10721968
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 17

Expert Comment

by:rstaveley
ID: 10722223
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
 
LVL 12

Expert Comment

by:stefan73
ID: 10722655
rstaveley,
Looks like CP/M is even more primitive:

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

Stefan
0
 
LVL 17

Expert Comment

by:rstaveley
ID: 10722880
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
 
LVL 9

Expert Comment

by:ankuratvb
ID: 10724405
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Which checksum is this? 7 143
How to set environment variables in C 2 82
sameEnds challenge 3 159
valid enum? 6 74
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question