0
How to compare two character arrays ?
character arrays
4 Réponses
+ 11
If you want to do it the manual way though:
bool is_equal = true;
if (size_of(array1) != size_of(array2))
{
is_equal = false;
}
for (int i = 0; i < (size_of(array1)/size_of(array1[0])); i++)
{
if (array1[i] != array2[i])
{
is_equal = false;
}
}
if (is_equal)
{
std::cout << "Arrays are equal.";
}
else
{
std::cout << "Arrays are not equal.";
}
+ 5
Use strcmp from the <cstring> header:
// strcmp returns 0 if the strings are equal
bool equal = strcmp(string1, string2) == 0;
+ 5
swapping
+ 3
string s = new string(a);
string t = new string(b);
int answer = string.Compare(s, t);
if(answer ==0)
{
//Equal
}