string removeSpaces (string input)
{
string output;
int n;
int o = 0;
for ( n = 0; n < (int)input.length(); n++ )
{
if (input[n] != ' ')
{
output[o] = input[n];
o++;
}
}
return output;
}
output[o] = input[n];
if(foo.at(bar) == 'foobar'){
foo.at(bar) = foobar.at(bar);
}
if( foo.find(' ') != std::string::npos ){ // if it's found
foo.at( foo.find(' ') ) = '_'; // replace a space with an underscore
}
if (input[n] != ' ')
{
output.append(input[n]); // adds a character to the end of output
}
string removeSpaces (string input)
{
string output;
int n;
int o = 0;
for ( n = 0; n < (int)input.length(); n++ )
{
if (input[n] != ' ')
{
output.append(input, o, 1);
o++;
}
}
return output;
}
//getNum returns integer value in base (base) of string input
int getNum (string input, int base)
{
input = removeSpaces(input);
int n;
int i = 0;
int total = 0;
int mult;
for ( n = 0; n < (int)input.length(); n++ )
{
if (numericChar(input[n], base) != NULL)
{
mult = numOfIntegers(input, base) - 1;
mult = mult - i;
mult = power((double)base, (double)mult);
mult = (mult * numericChar(input[n], base));
total = mult + total;
i++;
}
}
return total;
}
//power returns base^exponent as integer
double power (double base, double exponent)
{
if (exponent > (double)1) return base * (power(base, (exponent - 1)));
else if (exponent == (double)1) return base;
else if (exponent == (double)0) return (double)1;
else if (exponent < (double)0) return ( (double)1 / power(base, ((double)0 - exponent)));
return NULL;
}
//numOfIntegers returns number of integers in string input as integer
int numOfIntegers (string input, int base)
{
int n;
int total = 0;
for (n = 0; n < (int)input.length(); n++)
{
if (numericChar(input[n], base) != NULL) total++;
}
return total;
}
//removeSpaces returns string without spaces
string removeSpaces (string input)
{
string output;
int n;
int o = 0;
for ( n = 0; n < (int)input.length(); n++ )
{
if (input[n] != ' ')
{
output.append(input, o, 1);
o++;
}
}
return output;
}
//returns value of character up to base 16
int numericChar (char input, int base)
{
if (input == '0') return 0;
else if (input == '1') return 1;
if (base > 2)
{
if (input == '2') return 2;
if (base > 3)
{
if (input == '3') return 3;
if (base > 4)
{
if (input == '4') return 4;
if (base > 5)
{
if (input == '5') return 5;
if (base > 6)
{
if (input == '6') return 6;
if (base > 7)
{
if (input == '7') return 7;
if (base > 8)
{
if (input == '8') return 8;
if (base > 9)
{
if (input == '9') return 9;
if (base > 10)
{
if (input == 'A' || input == 'a') return 10;
if (base > 11)
{
if (input == 'B' || input == 'b') return 11;
if (base > 12)
{
if (input == 'C' || input == 'c') return 12;
if (base > 13)
{
if (input == 'D' || input == 'd') return 13;
if (base > 14)
{
if (input == 'E' || input == 'e') return 14;
if (base > 15)
{
if (input == 'F' || input == 'f') return 15;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return NULL;
}