hi all,
I am beginner in C, I want to execute any DOS command like
"cd <directory Name>"
"dir"
"cls" etc..... Through C program.
Please any can help me .
Thanz in advance.
hi all,
I am beginner in C, I want to execute any DOS command like
"cd <directory Name>"
"dir"
"cls" etc..... Through C program.
Please any can help me .
Thanz in advance.
You _Could_ do this, but there exists functions for EACH of these in several libs. . . Calling an external program from within your code is generaly considered to be "bad."
Have you tried something like the system command?
eg.
system("dir");
system("cd"); etc...
http://www.thinkage.ca/english/gcos/...ib/system.html
As stated, you could use the system() command but that's sort of OS dependant.
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
system() can also be dangerous. Imagine if someone mapped "cls" to "bad_trojan-2.5.exe" on some computer.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
Hence how it is considered to be "bad."
Aside from that, system("cd foo"); does NOT change the directory of the program itself, much to the surprise of newbies.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The POSIX function chdir() does, however.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.