warning C4996: '_strlwr': _strlwr_s

warning C4996: '_strlwr': This function or variable may be unsafe. Consider using _strlwr_s instead.

주의사항

  • _strlwr()의 경우, 리턴 값을 다른 함수의 인수로 사용할 수 있었는데, 변경된 함수에서는 errno_t가 리턴 된다.
  • 문자열의 크기를 넘겨주는 경우, 문자열 길이에서 널 터미네이터를 잊지 말자.

예제

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

int main()
{
   char szStr[] = "Hello World";
   char *pszStr;
   errno_t err;

   pszStr = _strdup(szStr);

   printf_s(">> Array example\n");
   printf_s("before: %s\n", szStr);
   // 배열의 경우
   err = _strlwr_s(szStr);
   printf_s(" after: %s\n", szStr);

   printf("\n>> Pointer example\n");
   printf("before: %s\n", pszStr);
   // 포인터의 경우
   err = _strlwr_s(pszStr, strlen(pszStr) + 1);
   printf(" after: %s\n", pszStr);

   free(pszStr);

   return 0;
}

결과

>> Array example
before: Hello World
 after: hello world

>> Pointer example
before: Hello World
 after: hello world

댓글 쓰기

0 댓글