J
Jenski182
Is this from a good coder? or a rubbish one? Whichever way, it was paid for his
services, just want to know if its worth while....
Thanks
Jen x
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
#include <direct.h>
void main()
{
char current_dir[50],tokens[10][20],input[300]; // for storing current
directory , tokens , and input
int i,j,k;
char x;
char dir_ex[30];
ifstream fin;
cout<<"\n\n\t\t *** COMMAND PROMPT *** \n\n ";
do // repeat till token = EXIT
{
_getcwd(current_dir,50); // gets current directory
cout<<"\n\n\n"<<current_dir;cout<<"> "; // puts it as a prompt
//cin>>input;
cin>>x;
gets(input); // reads command
//tokens[0][0] =NULL;
int length=strlen(input);
j=0;
for(i=0;i< length;i++) // do till end of command
{
k=0;
while( (input== ' ' )&&(i<strlen(input)) ) // parse command to tokens
based upon spaces
{
i++;
}
while( (input!= ' ' )&&(i<strlen(input)) )
{
tokens[j][k] = input;
k++;
i++;
}
tokens[j][k] = NULL;
cout<<"\n Token "<<j+1<<" : "<<tokens[j]; // show token
j++;
}
if( strcmpi(tokens[0],"DIR")==0) // if token is DIR
{
strcat(dir_ex,"DIR ");
strcat(dir_ex,tokens[1]);
strcat(dir_ex,NULL);
system( dir_ex);
cout<<"\n\n\t Listing directory : ";
cout<<" "<<current_dir<<"\n\n";
}
if( strcmpi(tokens[0],"PWD")==0) // if token is PWD
{
cout<<"\n\n\t Current directory : ";
cout<<" "<<current_dir<<"\n\n"; // puts it as a prompt
}
if( strcmpi(tokens[0],"CD")==0) // if token is CD
{
chdir(tokens[1]); // change directory
cout<<"\n\n\t Directory changed to : ";
getcwd(current_dir,50);
cout<<" "<<current_dir<<"\n\n"; // shows changed directory
}
if( strcmpi(tokens[0],"TYPE")==0) // if token is TYPE
{
fin.open(tokens[1]);
if(!fin)
{
cout<<"\n\n\n FILE NOT FOUND ! \n\n ";
}
else
{
cout<<"\n\n\n\t *** PRINTING FILE *** \n\n ";
while(!fin.eof()) // shows file contents
{
fin.read((char*)&x,1);
cout<<x;
}
}
fin.close();
}
if( strcmpi(tokens[0],"EXIT")==0) // if command is exit
{
exit(1);
}
}while(strcmpi(tokens[0],"EXIT")!=0);
}
services, just want to know if its worth while....
Thanks
Jen x
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fstream.h>
#include <direct.h>
void main()
{
char current_dir[50],tokens[10][20],input[300]; // for storing current
directory , tokens , and input
int i,j,k;
char x;
char dir_ex[30];
ifstream fin;
cout<<"\n\n\t\t *** COMMAND PROMPT *** \n\n ";
do // repeat till token = EXIT
{
_getcwd(current_dir,50); // gets current directory
cout<<"\n\n\n"<<current_dir;cout<<"> "; // puts it as a prompt
//cin>>input;
cin>>x;
gets(input); // reads command
//tokens[0][0] =NULL;
int length=strlen(input);
j=0;
for(i=0;i< length;i++) // do till end of command
{
k=0;
while( (input== ' ' )&&(i<strlen(input)) ) // parse command to tokens
based upon spaces
{
i++;
}
while( (input!= ' ' )&&(i<strlen(input)) )
{
tokens[j][k] = input;
k++;
i++;
}
tokens[j][k] = NULL;
cout<<"\n Token "<<j+1<<" : "<<tokens[j]; // show token
j++;
}
if( strcmpi(tokens[0],"DIR")==0) // if token is DIR
{
strcat(dir_ex,"DIR ");
strcat(dir_ex,tokens[1]);
strcat(dir_ex,NULL);
system( dir_ex);
cout<<"\n\n\t Listing directory : ";
cout<<" "<<current_dir<<"\n\n";
}
if( strcmpi(tokens[0],"PWD")==0) // if token is PWD
{
cout<<"\n\n\t Current directory : ";
cout<<" "<<current_dir<<"\n\n"; // puts it as a prompt
}
if( strcmpi(tokens[0],"CD")==0) // if token is CD
{
chdir(tokens[1]); // change directory
cout<<"\n\n\t Directory changed to : ";
getcwd(current_dir,50);
cout<<" "<<current_dir<<"\n\n"; // shows changed directory
}
if( strcmpi(tokens[0],"TYPE")==0) // if token is TYPE
{
fin.open(tokens[1]);
if(!fin)
{
cout<<"\n\n\n FILE NOT FOUND ! \n\n ";
}
else
{
cout<<"\n\n\n\t *** PRINTING FILE *** \n\n ";
while(!fin.eof()) // shows file contents
{
fin.read((char*)&x,1);
cout<<x;
}
}
fin.close();
}
if( strcmpi(tokens[0],"EXIT")==0) // if command is exit
{
exit(1);
}
}while(strcmpi(tokens[0],"EXIT")!=0);
}