-1
#define __STDC_WANT_LIB_EXT1__ 1
#define __STDC_LIB_EXT1__ 1
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
int main() {
    // Write C code here
    printf("Hello world");
    char* key="";
    char* key1="";
    char curr[5] = "abcd";
    strncpy_s(key, 68, curr,67);
    strncpy_s(key1, strlen(curr), curr,strlen(curr));
    printf("%s \n%s",key,key1 );

    return 0;
}

I tried online compilers https://www.tutorialspoint.com/compile_cpp11_online.php https://www.programiz.com/c-programming/online-compiler/

I tried g++ abc.cpp -std=c++11

still getting

abc.cpp:13:31: error: ‘strncpy_s’ was not declared in this scope
     strncpy_s(key, 68, curr,67);
Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
Ek1234
  • 407
  • 3
  • 7
  • 17
  • All the `_s` c string functions are only implemented by Microsoft, though they've now been added to the c standards they're optional and nobody else has implemented them – Alan Birtles Aug 28 '23 at 05:20
  • `__STDC_LIB_EXT1__` isn't to be defined by you but a theoretical compiler supporting Annex K bounds-checking interfaces, which will probably never happen. But here's the good news: if you pick a C23 compiler (like gcc `-std=c2x`) then you can use `memccpy` instead. Usage: `memccpy(dst, src, '\0', max_size);` – Lundin Aug 28 '23 at 06:33
  • 1
    The functions from Annex K are part of the C Standard with optional support. They are available only on selected platforms and Microsoft's implementation for Windows follows an earlier API that does not conform to the Standard version, hence their use is not recommended for portable software. The warning about deprecation of *non-secure* standard string functions can be disabled by defining `#define _CRT_SECURE_NO_WARNINGS` before including the standard header files. – chqrlie Aug 28 '23 at 08:57

0 Answers0