Write a c program to create open command which is similar to type command in dos operating system?
Ans:
#include
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 India.c
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.

0 comments:

Followers

 
C - Programming -