Computing.Net > Forums > Programming > dos commands in a C program

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

dos commands in a C program

Reply to Message Icon

Name: RSephroth
Date: June 10, 2003 at 18:44:12 Pacific
OS: .
CPU/Ram: .
Comment:

I am new to C so be easy on me! :|

I know it sounds stupid but i'm trying to make a program that basically works just like the msdos prompt. I wont go into why. But the problem i'm having is that it screws up with any commands entered that have a space. For example "ipconfig/all" works fine but "copy xxx xxx" doesn't. What it does is interpret any objects seperated by a space as seperate commands. It is a very simple program here it is:

#include
using namespace std;

void main()
{
char command[500];

cout ";
cin.getline( command, 500, '\n' );
cout endl endl;
system (command);
goto loop;
}

now whats wierd is if you manually enter in the command in the system line ie:
system("copy xx xx")
it works perfectly fine even with the spaces.
So does anyone know why this happens and how to fix it?

PS: all my cout lines got screwed up because the have the greater-than less-than symbols in them. They accually are coded right on my end.



Sponsored Link
Ads by Google

Response Number 1
Name: RSephroth
Date: June 10, 2003 at 18:46:35 Pacific
Reply:

also there is a "loop:" marker above where you enter the command but it got deleted too i guess because of the html.


0

Response Number 2
Name: egkenny
Date: June 10, 2003 at 20:16:30 Pacific
Reply:

Since parts of your program are missing I had to guess what they were. I tested this program with Visual C++ 6.0 under Windows XP and GCC 3.1 under RedHat Linux 9. My version of your program work fine. BTW, to post code:
1) Enter text part of message
2) Select "Submit Follow Up"
3) Select "Click Here" at top of page
4) Paste your code in text box
5) Select "Convert"
6) Paste converted code below
7) Select "Confirm Post"
#include <iostream>
using namespace std;

int main()
{
    while(1)
    {
         char command[500]="";
         cout << "$ ";
         cin.getline( command, 500, '\n' );
         cout << endl << endl;
         system (command);
    }
    return 0;
}


0

Response Number 3
Name: RSephroth
Date: June 10, 2003 at 20:27:06 Pacific
Reply:

Hmm thats wierd, my program should have done exactly the same thing as yours, but your's works, and mine doesn't, I bow down to your mightyness!

Oh yeah and thanks! :)

and now that i know how here is the original program in full form:

#include <iostream>
using namespace std;

void main()
{
 char command[500];
      
 cout << "School Prompt v1.0" << endl
       << "Written by: Fenestra" << endl << endl << endl;
loop:
 cout << "<|>";
 cin.getline( command, 500, '\n' );
 cout << endl << endl;
 system (command);
 goto loop;
}


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: dos commands in a C program

simulation of wc in a c program www.computing.net/answers/programming/simulation-of-wc-in-a-c-program/13560.html

Using a c++ lib from a c program. www.computing.net/answers/programming/using-a-c-lib-from-a-c-program/4125.html

how to use Dos commands in Borlad C www.computing.net/answers/programming/how-to-use-dos-commands-in-borlad-c/4175.html