I am trying to create a function that will replace 0, 1 or 2 spaces in a string. I am going to do this by repeating a line and comparing each individual character.
My function will work if I compare str_in [i] == '0' , but if I add either an operator, it will not return anything.
Excerpt:
string omit_num( string ) {
int i ;
str_len = str_in.length();
str_out = "" ;
for( i = 0 ; i < str_len ; i ++ ){
cout << str_in[i] << endl;
if ( str_in[i] == '0' || '1' || '2')
app = " " ;
else
app = str_in[i];
str_out.append(app) ;
}
return str_out;
}
source
share