I have a uni project and i need some help!
i have to develop an MS-DOS command prompt emulations, that has the following dos commands:
CLS
VER
DIR
CD
DOSKEY
HELP
EXIT
ANY IDEAS??
thank u
Printable View
I have a uni project and i need some help!
i have to develop an MS-DOS command prompt emulations, that has the following dos commands:
CLS
VER
DIR
CD
DOSKEY
HELP
EXIT
ANY IDEAS??
thank u
Yeah, start working. Then post some code when you're having trouble.Quote:
Originally Posted by panagiotis13
Because wandering from board to board has been so productive so far.
http://forums.devshed.com/c-programm...ed-347717.html
How about actually showing what you've managed to achieve so far. You're at university now, not pre-school, show some initiative for goodness sake.
I mean, being able to read in a command and print it back out as say "you typed CD" would at least show that you've made some effort and have a grasp of the basics.
i really don know how to start...
any tips??
Open your compiler, then create a new source file...
couldnt you use the system("dos command") using a switch statement in dev-c
just a thought, am doing A level computing so im not an expert.
They want him to emulate the commands, not call them. :)
And besides, I'd imagine this is being done on Sun OS or something similar that doesn't have those particular commands (atleast by that name).
QUESTION:
create one program for each commad? let's say, CD.EXE, DOSKEY.EXE etc?
or create a single program, that reads the input from the user and calls the right fuction for each command, using IF (If input=CLS then ... )
> i really don know how to start...
How about starting with the "EXIT" command?
That ought to be easy enough.
Or carefully study your previous programming assignments for clues. These things tend to build on knowledge acquired in previous classes and assignments.
Unless of course you got someone else to do those as well, in which case you're just in free fall :rolleyes:
ok done something... check out my code:
So far, HELP, CLS, VER and EXIT commands seem to work.Code:#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;
int main()
{
string x;
getline (cin,x);
do{
if (x=="help")
{
string line;
ifstream myfile ("help.txt"); //Reads the text from a help file
if (myfile.is_open())
{
while (! myfile.eof() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
break;
}
if (x=="cls") //The CLS command, it seems to work fine...
{ system("CLS");
break;
}
if (x=="ver") //This is the VER command, it displays the version of my program!
{
cout << "Pan O.S. Version 1.0 April 2006 ALL RIGHTS RESERVED\n";
}
break;
}
while (x!="exit"); //done with EXIT command
cin.get();
return 0;
}
I really need some help on CD and DIR commands. And i have an other problem:
How can i keep the command window open for more than one command? When my program runs, it works only for the first command. It exits when i type the next command.
Thank you
See - that wasn't too bad, now we're getting somewhere.
> How can i keep the command window open for more than one command?
This should be inside your while loop, otherwise you can only enter one command.
> getline (cin,x);
> I really need some help on CD and DIR commands
http://faq.cprogramming.com/cgi-bin/...&id=1044780608
The chdir() call is basically your CD command, and a loop calling findfirst / findnext is your DIR command.
Can you explain me this a little more please? I really need some help!Quote:
Originally Posted by Salem
Thank you
chdir() changes your working directory (and getcwd() tells you your current working directory). Those two functions will take care of your CD command.
You can use opendir(), readdir(), and closedir() to emulate the DIR command. (Or findfirst etc.)
If you don't know anything about a function, use man or google:
Code:$ man readdir
As for DOSKEY . . . I guess that means you can enter something like "command 1" and it will repeat command 1. You'll need to store the previous commands. Try a vector.Code:google for "readdir"
> Can you explain me this a little more please?
Well something like
Code:if ( x == "cd" ) {
string whereToCdTo;
cin >> whereToCdTo;
chdir( whereToCdTo.c_str() );
}
Ok vector it is! so i try this:Quote:
Originally Posted by dwks
What I did wrong? My program runs, but when i type something, the command window closes.Code:#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <windows.h>
#include <dir.h>
#include <vector>
using namespace std;
using std::string;
int main()
{
string x;
std:: vector <std::string> doskey_vector;
do{
cout << "OS>";
getline (cin,x);
int j;
for (j = 0; j < 20; j++)
doskey_vector.at(j) = x;
...
...
I want to store let's say, the last 10 commands that the user types, and then use DOSKEY to view them. Any help??
Thank u
You may have to use doskey_vector.push_back(x) instead.Code:doskey_vector.at(j) = x;
like this?Quote:
Originally Posted by laserlight
I want to store the current value of variable x, to the vector. So every time the user types a command, the command will be stored, and the next one and so on...Code:doskey_vector.at(j) = doskey_vector.push_back(x);
Thank you
No, just use the push_back() member function.
You may want to read cppreference.com's article on vectors, and also check out SGI's Standard Template Library Programmer's Guide.
Like this:
Code:doskey_vector.push_back(x);