First, strupr
is not part of the standard C library nor the standard C++ library. So there is no standard header that is required to declare it.
That said, it started out as a Microsoft thing, and was, indeed, declared in <string.h>
. See this question for more discussion.
So, unless your compiler has it as an extension, it won't exist. That's what the error message is telling you.
Even if it does exist, you can't use it the way that the code in the question tries to do. The problem is that it modifies the contents of its argument, so you can't pass a const char*
to it. That's what this code does:
strupr("hello world");
"hello world"
is a string literal, and in the olden days its type was char[12]
, that is, formally, it looked like a modifiable string. But in fact, it was up to the compiler to decide whether string literals were modifiable, so with some compilers it was okay and with others it wasn't. When it wasn't, it would be because the compiler put string literals in read-only memory, so attempting to modify the literal would produce a runtime error.
In C++, the type of "hello world"
is const char[12]
, that is, the characters in the string are not modifiable. So calling strupr("hello world")
is ill-formed, and the compiler should issue a diagnostic.
To make it work, if your compiler provides this function, you have to call it on a modifiable string:
char str[] = "hello world";
strupr(str);
str
is a modifiable array of char
that holds a copy of the text in its initializer, in this case, "hello world"
. That string can be modified, so strupr
can do its job.