Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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.

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

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;
}

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;
}

![]() |
![]() |
![]() |

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