Hey i'm trying to use this trim function i wrote but its going wrong for me. I can trim from the front but not behind, e.g. if i enter **bob it works but if i enter **bob** it just prints nothing. please help
#include <iostream>
using namespace std;
void trimFunction( string & fileName, string & editFileName, string & properFileName);
void main()
{
string fileName, editFileName, properFileName;
cout << "Enter fileName"<<endl;
getline(cin, fileName);
trimFunction( fileName, editFileName, properFileName);
}
void trimFunction( string& fileName, string& editFileName, string& properFileName){
int i = fileName.length()-1;
int endStr =i;
int numChars=0;
char ch;
ch = fileName.at(i); //gets end of fileName char
cout <<"i "<<i<<endl;
while(ch !='*' && i >=0)
{
i--;
cout <<"i loop "<<i<<endl;
ch = fileName.at(i);
cout<< "Ch = " << ch <<endl;
}
numChars = endStr -i;
editFileName = fileName.substr(i+1, numChars);
cout << "File Name before editing "<< fileName <<endl;
cout << "File Name after editing "<< editFileName << endl;
int startAddress =0;
int j = fileName.length();
int numChars2 = j - startAddress ;
char ch2;
ch2 = fileName.at(j);
while( ch2 !='*' && j < fileName.length() )
{
j++;
cout <<"i loop "<<j<<endl;
ch2 = fileName.at(j);
cout<< "Ch = " << ch <<endl;
}
properFileName = fileName.substr(j-1, numChars2);
cout << "Edit File Name after editing "<< properFileName << endl;
}