|
From: Linda H. <lz...@sp...> - 2001-05-01 20:28:39
|
Hi All,
Can anyone help me with a couple of functions I am having problems with =
in the String class I am writing? (It runs.)
The following code is supposed to return the first instance of a =
character, but is returning the last (11):
int String::firstcharfind (const char& charfind) const //#2
{ size_t i;
int position;
for (i =3D 0; i < current_length; i++)
{
if (sequence[i] =3D=3D charfind)
position =3D i;
}
return position;
}
This is called by:=20
//#2
char testing [28] =3D "Delete the extra word word.";
String demostring (testing);
cout << demostring.firstcharfind ('e') << endl;
The second function is supposed to delete one of the "word"s in the =
above function:
bool String::charsdelete (int begin, int end) //#4
{
int i;
if ((begin < 0) || (end > current_length) || (begin > end))
return false;
int partdeleted =3D (end - begin) + 1;
for (i =3D begin; i <=3D current_length - partdeleted ; i++)
{
sequence[i] =3D sequence[partdeleted + 1];
}
current_length =3D current_length - partdeleted;
allocated =3D allocated - partdeleted;
return true;
}
It's called by:
//#4
demostring.charsdelete (18, 22);
cout << demostring << endl;
The output is:
Delete the extra w ord.
I'd appreciate any help anyone can give - it's the last class for my =
Data Structures class.
TIA,
Linda
|