i am using strrev function and also included the header file string.h but i am getting the compile error
‘strrev’ was not declared in this scope.
what else is required?
i am using strrev function and also included the header file string.h but i am getting the compile error
‘strrev’ was not declared in this scope.
what else is required?
This error happens because strrev is not part of the C or C++ standard libraries. Some Windows toolchains expose Microsoft’s nonstandard _strrev, so it can appear to work locally (e.g., certain Dev-C++ setups) but fail on stricter compilers and online judges. The standard <string.h> does not include strrev, which is why you see the compile error. See the C header list for confirmation, and Microsoft’s docs for the vendor-specific _strrev. C <string.h> functions. MSVC _strrev.
As and said, write your own. Here’s a small, portable C version that works in place:
#include <string.h>
char *strrev_inplace(char *s) {
if (!s) return NULL;
size_t i = 0, j = strlen(s);
if (j == 0) return s;
for (--j; i < j; ++i, --j) {
char t = s[i];
s[i] = s[j];
s[j] = t;
}
return s;
} Notes:
char buf[] = "hello"; strrev_inplace(buf);strrev_inplace("hello"); // modifies read-only storageIf you’re actually compiling as C++ (your error text suggests g++), prefer the standard algorithm instead of strrev:
#include <algorithm>
#include <string>
std::string s = "hello";
std::reverse(s.begin(), s.end()); // portable Reference for std::reverse: std::reverse.
This aligns with ’s and ’s points: portability beats extensions, especially on judge systems.
Jump to Post— rithish 13can i know wat compiler r u using???
Jump to Post— rithish 13some times the compilerdirectory may not have string.h libraray functions.the same problem i had in alloc.h
can i know wat compiler r u using???
some times the compilerdirectory may not have string.h libraray functions.the same problem i had in alloc.h
strrev() isn't a standard function, so compilers aren't obligated to support it. What compiler are you using?
You can always write your own strrev().
in dev-c++ it works fine.
but the problem is when i submit the code on site. it gives me compile error.
Then, as deceptikon says, it's not supported by that compiler. Write your own.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.