Click to See Complete Forum and Search --> : Dynamically created arrays


elias
03-09-2002, 02:44 PM
I have a problem that I have coded, but I am not sure if I did it correctly.
The problem is comparing two dynamically created arrays of characters for
equality. I am trying to use pointers instead of <string>. Since I can not
enclose the files in this forum, I will need a response with an email address
to send the code for you to look at.

Danny Kalev
03-10-2002, 04:41 AM
elias wrote:
>
> I have a problem that I have coded, but I am not sure if I did it correctly.
> The problem is comparing two dynamically created arrays of characters for
> equality. I am trying to use pointers instead of <string>. Since I can not
> enclose the files in this forum, I will need a response with an email address
> to send the code for you to look at.

you can copy and paste the code as text in your message. You don't need
to attach files. When you paste code, please be brief. Some folks attach
entire applications without even indicating what the problem is,
thinking we have nothing else to do but debug and run their programs.

Danny

Al Gruber
03-11-2002, 02:38 PM
>elias wrote:
>>
>> I have a problem that I have coded, but I am not sure if I did it correctly.
>> The problem is comparing two dynamically created arrays of characters
for
>> equality. I am trying to use pointers instead of <string>. Since I can
not
>> enclose the files in this forum, I will need a response with an email
address
>> to send the code for you to look at.
>

I seem to remember this is the usual "clever" code to compare 2 0-terminated
char arrays. If I'm wrong, I'm sure somebody will tell us.

bool stringSame(char * array1, char * array2) {
while (*array1++ == *array2++)
if (!*array1)
return true;//cause return when 0-terminator is reached
return false; //causes return when while false
}

Given arrays named a1 and a2, call like this:
cout << "stringSame:" << stringSame(a1,a2) << endl;

Good luck, Al