Start New Discussion within our Software Development Community

This filters out the letters and numbers in the parameters you give it.

#include <iostream>
#include <string>

using namespace std;

int main (int argc, char* argv[])
{
	string input;
	string chars;
	string nums;

	for(int i=1; i<argc; i++)
	{
		input = argv[i];
#ifdef debug
		cout << endl << "Input is : " << input << endl;
#endif
		string tempChar(input.size(),0);
		string tempNum(input.size(),0);

		for(string::size_type j=0; j<input.size(); j++)
		{
#ifdef debug
			cout << endl << "Currently processing this char : " << input[j] << endl;
#endif
			static int numChar = 0;
			static int numNums = 0;
			bool found = false;
			for(int k=48; k<58; k++)
			{
#ifdef debug
				cout << endl << "Looking for : " << char(k) << endl;
#endif
				if(input.c_str()[j] == char(k))
				{
					found = true;
#ifdef debug
					cout << endl << "Found char : " << char(k) << endl;
#endif
					break;
				}
			}
			if(!found)
			{
				tempChar[numChar] = input[j];
				numChar++;
			}
			else
			{
				tempNum[numNums] = input[j];
				numNums++;
			}
		}
		chars = tempChar;
		nums = tempNum;
		cout << endl << "Letters in input are : " << chars << endl;
		cout << endl << "Numbers in input are : " << nums << endl;
	}
}