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
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.Originally Posted by panagiotis13
Sent from my iPadŽ
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i really don know how to start...
any tips??
Open your compiler, then create a new source file...
Sent from my iPadŽ
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).
Sent from my iPadŽ
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
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Can you explain me this a little more please? I really need some help!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 readdirAs 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"
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
> Can you explain me this a little more please?
Well something like
Code:if ( x == "cd" ) { string whereToCdTo; cin >> whereToCdTo; chdir( whereToCdTo.c_str() ); }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Ok vector it is! so i try this: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