File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 11#include < iostream>
22#include < string>
33
4+ void do_exit (std::string args) {
5+ int exit_code = std::stoi (args);
6+ exit (exit_code);
7+ }
8+
9+ void do_echo (std::string args) {
10+ std::cout << args << std::endl;
11+ }
12+
413int main () {
514 // Flush after every std::cout / std:cerr
615 std::cout << std::unitbuf;
@@ -13,9 +22,12 @@ int main() {
1322 std::string cmd = input.substr (0 , input.find (' ' ));
1423 std::string args = input.substr (input.find (' ' ) + 1 );
1524 if (cmd == " exit" ) {
16- exit (std::stoi (args));
25+ do_exit (args);
26+ }
27+ else if (cmd == " echo" ) {
28+ do_echo (args);
1729 }
18- if (input != " " ) {
30+ else if (input != " " ) {
1931 std::cout << input << " : command not found" << std::endl;
2032 }
2133 } while (input != " " );
You can’t perform that action at this time.
0 commit comments