![]() |
| | #1 |
| Registered User Join Date: Nov 2005
Posts: 36
| Question about the System() function... Code: #include <iostream>
#include <stdlib.h>
#include <string>
void main()
{
char cmd[100] = " ";
cout << "Please enter command: ";
cin.getline(cmd, 100);
while (strcmp (cmd, "exit") !=0)
{
system (cmd);
cout << "Please enter command: ";
cin.getline(cmd,100);
}
exit(1);
}
|
| YankeePride13 is offline | |
| | #2 |
| Registered User Join Date: Nov 2005
Posts: 36
| this is the updated code... Code: #include <iostream>
#include <stdlib.h>
#include <string>
#include <unistd.h>
void main()
{
char cmd[100] = " ";
char * pch;
cout << "Please enter command: ";
cin.getline(cmd, 100);
while (strcmp (cmd, "exit") !=0)
{
if((cmd[0] == "c") && (cmd[1] == "d"))
{
pch = strtok(cmd," ");
pch = strtok(NULL," ");
chdir(pch);
}
else
{
system (cmd);
cout << "Please enter command: ";
cin.getline(cmd,100);
}
}
exit(1);
}
test.cpp:16: ISO C++ forbids comparison between pointer and integer test.cpp:16: ISO C++ forbids comparison between pointer and integer any ideas? |
| YankeePride13 is offline | |
| | #3 |
| Me Join Date: Oct 2002 Location: Europe
Posts: 448
| You're getting those errors because you're comparing a string (char pointer) and an int. You should change the line that says Code: if((cmd[0] == "c") && (cmd[1] == "d") Code: if((cmd[0] == 'd') && (cmd[1] == 'd') Also, please change the return value of main to int. Void is just wrong (see the FAQ or search the forums for the reason(s)). It might be better to fork() and then exec(), but that's a bit more complicated.
__________________ SoKrA-BTS "Judge not the program I made, but the one I've yet to code" I say what I say, I mean what I mean. IDE: emacs + make + gcc and proud of it. |
| -=SoKrA=- is offline | |
| | #4 |
| Registered User Join Date: Sep 2004
Posts: 197
| Im wondering why you wouldn't be getting errors with this, since cin and cout are in the std namespace, and I don't see a "using namespace std;" or any thing like that in your code. Also, its int main, not void.
__________________ If any part of my post is incorrect, please correct me. This post is not guarantied to be correct, and is not to be taken as a matter of fact, but of opinion or a guess, unless otherwise noted. |
| Xipher is offline | |
| | #5 |
| Me Join Date: Oct 2002 Location: Europe
Posts: 448
| He's probably using some very permissive compiler. My g++ erros out on void main(). Also, I suspect this is not the code verbatim, because the line where he's got the error and it's actual line in the code he posted are different.
__________________ SoKrA-BTS "Judge not the program I made, but the one I've yet to code" I say what I say, I mean what I mean. IDE: emacs + make + gcc and proud of it. |
| -=SoKrA=- is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| question abt function system(); | errtime | C Programming | 2 | 10-01-2007 01:24 PM |
| Screwy Linker Error - VC2005 | Tonto | C++ Programming | 5 | 06-19-2007 02:39 PM |
| measuring system resources used by a function | Aran | C Programming | 1 | 03-13-2006 05:35 PM |
| Including lib in a lib | bibiteinfo | C++ Programming | 0 | 02-07-2006 02:28 PM |
| [question]Simulating the Reliability of a Component-Based System | burbose | C Programming | 3 | 06-13-2005 07:28 AM |