It looks like you want to compare strings after sorting. Assuming your sort
function does the right thing, you need to compare the strings after sorting them.
sort(string1);
sort(string2);
val = strcmp(string1, string2);
The reason for the error is that your sort
function returns void
. So you are effectively passing void
arguments to strcmp
. And that can’t work.
The way to do this in C++ would be to use std::string
, and call std::sort
.
std::string string1, string2;
std::cout << "Enter first string";
std::cin >> string1;
std::cout << "Enter second string";
std::cin >> string2;
std::sort(string1.begin(), string1.end());
std::sort(string2.begin(), string2.end());
bool val = string1 == string2;
2
solved Invalid use of void expression in strcmp