Sprintf (?)

(sorry for my bad english.. english isn't my native language)

so, i'm creating a copy files program.. and a friend of mine said that if I use sprintf to copy, just like this \/ it will do de copy.. but it doesnt work.. =\

sprintf(comand, "xcopy %s %s", cp, cp2);

note: cp = where the file is;
cp2 = where i want the file to be copied;
comand = is a string(char comand[100];

but, when i compile and run the source code, it crashes... why?

Ty. And sorry for my bad english(haha)
"comand" has space only for 100 characters. Are you sure the length of the resulting string is always below that limit ?
sprintf writes to an array/string not to a file int sprintf ( char * str, const char * format, ... );

Try using int fprintf ( FILE * stream, const char * format, ... );

E: Also paste the source code here. I want to see what xcopy is because that might also be contributing to crashing your program.
Last edited on
Topic archived. No new replies allowed.