Skip to main content
gamedev.net
🔒 Locked

C++ console Looping Input problem

Started by waterboy4800 Dec 7, 2005 at 6:58 PM 2 replies 300+ views
Original Post
waterboy4800
waterboy4800
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;						
		}	



waterboy4800
waterboy4800
Thanks for that portion, but its the get line thats messeing it up, the strtok it doing the jon it is supose to do, the get line it cutting it off. I've ran the debug and steped thro plenty of times before it gets to the strtok and i can see the cmd_ is not correctly parsed from the input.

Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.