Original Post
Hello there, trying to write my own command prompt type thing for a console ftp program and im having troubles looping input. The first time it works great, the second time it does not completly parse the whole thing typed in. I do not want it to ignore white space so i use cin.getline. Example; >>dir i get "dir" and everything runs fine (second iteration) >>dir i get "di" and its an invalid type
bool exit = false;
while (!exit)
{
cout << ">>";
char cmd_[100];
cin.getline( cmd_, 100 );
vector<char*> arg;
for (char* token = strtok(cmd_, " "); token != NULL; token = strtok(NULL, "/n"))
arg.push_back( token );
int cmd = ftp::getCMD( arg[0] );
if ( cmd )
{
switch ( cmd )
{
case dir: RemoteDir(); break;
case ldir: LocalDir(); break;
case cd: if ( (int)arg.size() == 2 ) ChangeRemoteDir( arg[1] ); break;
case lcd: if ( (int)arg.size() == 2 ) ChangeDir( arg[1] ); break;
case pwd: PrintWorkingDir(); break;
case lpwd: PrintWorkingRemoteDir(); break;
case put: break;
case get: break;
case type: break;
case bye: exit = true; break;
}
}
else
cout << "Invalid Command, Try /help for a list of commands" << endl;
}