To Run a DOS command using C we use the system() function present in process.h and stdlib.h
The prototype of the function is:
Example:
The prototype of the function is:
int system(const char *command);
On Success returns 0
On Error returns -1Example:
#include<stdio.h> #include<conio.h> void main() { clrscr(); int i; printf("This program will execute the DOS command"); i=system("dir"); if(i==0) printf("completed successfully"); else printf("error in executing the command"); getch(); }If you are using turboc3 and run this using Ctrl+F9 you will not see the error , to run this go to cmd prompt and then execute the exe file created after compiling the program form the DOS prompt.you will easily get the output..if you are having any problem...just mail me at milankmr2011@gmail.com
No comments:
Post a Comment
Feel free to comment......