Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are strupr() and strlwr() in string.h part of the ANSI standard?

Tags:

c

string.h

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?

like image 208
exsnake Avatar asked Oct 12 '14 17:10

exsnake


3 Answers

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

  • strlwr() doc
  • strupr() doc

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;
}
like image 143
Michael Burr Avatar answered Nov 12 '22 05:11

Michael Burr


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

like image 45
Vlad from Moscow Avatar answered Nov 12 '22 05:11

Vlad from Moscow


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.

like image 1
R.. GitHub STOP HELPING ICE Avatar answered Nov 12 '22 05:11

R.. GitHub STOP HELPING ICE