Create dos command: type in c language.

#include “stdio.h”

void main(int count,char * argv[])

{

int i;

FILE *ptr;

char *str;

char ch;

if(count==1)

{

printf("The syntax of the command is incorrect.\n");

}

for(i=1;i

{

ptr=fopen(argv[i],"r");

if(ptr==NULL)

{

printf("The system cannot find the file specified.");

if(count>2)

printf("\nError occurred while procesing : %s.\n",argv[i]);

}

else

{

if(count>2)

{

printf("%s\n\n",argv[i]);

}

while((ch=getc(ptr))!=-1)

printf("%c",ch);

}

fclose(ptr);

}

}

Save the above file as open.c, compile and execute the go to command mode (current working directory) and write: open xy.c (xy.c any file present in that

directory)

To run the open 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 open command will work in all directory and drive.

No comments: