7

I was looking for this on internet and in every place with the functions of string.h these two are not mentioned.

Is because what? They aren't in every compiler?

ks1322
  • 33,961
  • 14
  • 109
  • 164
exsnake
  • 1,767
  • 2
  • 23
  • 44

3 Answers3

16

They are non-standard functions from Microsoft's C library. MS has since deprecated them in favor of renamed functions _strlwr() and _strupr():

Note that the MS docs claim they are POSIX functions, but as far as I can tell they never have been.

If you need to use them on a non-MS toolchain, they're easy enough to implement.

char* strlwr(char* s)
{
    char* tmp = s;

    for (;*tmp;++tmp) {
        *tmp = tolower((unsigned char) *tmp);
    }

    return s;
}
AJM
  • 1,317
  • 2
  • 15
  • 30
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • They're also supported by gcc, even if you try to force standards-compliance with something like `-std=c11`. – AJM May 05 '21 at 17:34
  • Regarding them being POSIX functions - there's a searchable online version of POSIX.1-2017 hosted at https://pubs.opengroup.org/onlinepubs/9699919799/ - and they're definitely not mentioned in it. – AJM May 05 '21 at 19:58
  • Also, you might want to add `#include ` in that code snippet, since `tolower` needs it and `strlwr` needed `` instead. – AJM May 05 '21 at 20:03
  • `_strlwr` and `_strupr` will illicit compiler warning C4996 (Your code uses a function, class member, variable, or typedef that's marked deprecated) in Visual Studio 2022 which suggests using `_strlwr_s`, `_strupr_s` instead. – chikega Sep 23 '22 at 21:01
4

These functions are not C standard functions. So it is implementation-defined whether they are supported or not.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
1

These functions are not standard, and in fact their signatures are broken/non-usable. You cannot case-map a string in-place in general, because the length may change under case mapping.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711