Jan 18, 2013 at 6:12pm UTC
Hello!
(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);
system(comand);
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)
Jan 18, 2013 at 7:04pm UTC
"comand" has space only for 100 characters. Are you sure the length of the resulting string is always below that limit ?
Jan 18, 2013 at 7:40pm UTC
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 Jan 18, 2013 at 7:44pm UTC