Why strcpy_s is safer than strcpy?

前端 未结 3 1768
天涯浪人
天涯浪人 2021-01-28 15:15

When I am trying to use the strcpy function the visual studio gives me an error

error C4996: \'strcpy\': This function or variable may be unsafe. Co         


        
3条回答
  •  鱼传尺愫
    2021-01-28 15:35

    The header definiton for C is:

    errno_t strcpy_s(char *dest,rsize_t dest_size,const char *src)
    

    The invocation for your example should be:

    #include 
    
    char a[50] = "void";
    char b[3];
    strcpy_s(b, sizeof(b), a);
    printf("String = %s", b);
    

提交回复
热议问题