Write a c program to create list command which is similar to dir command in dos operating system?
Ans:
#include
#include
void main(int count,char *argv[])
{
struct find_t q ;
int a;
if(count==1)
argv[1]="*.*";
a = _dos_findfirst(argv[1],1,&q);
if(a==0)
{
while (!a)
{
printf(" %s\n", q.name);
a = _dos_findnext(&q);
}
}
else
{
printf("File not found");
}
}

Save the above file as list.c ,compile and execute the go to command mode (current working directory) and write: list *.c
To run the list command in all directories and drive you will have to give the path of current working directory in command mode. write:
C:tc\bin>PATH c:\tc\bin
Now press enter key. Now your list command will work in all directory and drive.
In same way you can create cls ,copy con etc commands.


0 comments:

Followers

 
C - Programming -