I have to copy the string using strcpy_s
in my assignment.
The error undefine reference to 'strcpy_s' appears and cannot be executed.
strcpy
is available without any problems.
I've been searching for error codes for about an hour, but I haven't been able to solve them due to my lack of ability.
I would appreciate it if you could give me an explanation.
Environment
Ubuntu 20.04
exclude IDE
Here's the code:
#include<stdio.h>
# include <string.h>
int main() {
char A[10];
char B[10];
printf("Enter String\n");
scanf("%s",B);
printf("Replace string\n";
US>strcpy_s(A,sizeof(A),B);// Cannot run
// strcpy(A,B); // Can run
// strncpy(A,B,sizeof(A)); // Can be done
printf("A=%s",A);
return 0;
}
strcpy_s()
is a new function originally adopted by Microsoft Visual C/C++
.Therefore, strcpy_s()
is not often implemented for processing systems other than MSVC
.
c11 I mean, C language specification ISO/IEC9899:2011 was adopted optionally, but
https://stackoverflow.com/questions/40045973/
https://stackoverflow.com/questions/36723946/
Therefore, strcpy_s()
cannot be used in libc provided by the gcc development group.That is, the ubuntu libc cannot use strcpy_s()
(If it's a challenge, there should be a designation of the development environment. Visual Studio should be able to pass honestly, but isn't it specified?
strcpy_s()
is not in Ubuntu's libc, but if you want to use it on Ubuntu,
You have a choice.You can use safelib
as already mentioned, or copy .h
and .c
from MSVC
.cpp (which you haven't found yet).strcpy_s()
specification is everywhere, so if you can make the most of it.
Eclipse works on Windows, so the operating platform is Windows 10 integrated development environment is Eclipse compiler and library is MSVC.
Well, if it's a task, it's over if you finish it on Visual Studio, so I don't have to spend that much time (=cost), do I?
If you really want to implement strcpy_s on the eclipse, is there any way to force the code through and add functions?
774RR has also responded, but strcpy_s
is optional in the C language specification, and currently only available on Microsoft Visual Studio.
As a third party other than the questioner, I don't know what kind of description is actually saying, "You must copy the string using strcpy_s
in the assignment", but I suggest you read the assignment in depth again (
This is because the questionnaire uses printf
and scanf
, but it also has printf_s
and scanf_scode.It should be.
Also, since the _s
function in the C language specification and the _s
function in Visual Studio have subtle differences in specifications, it is better to clarify which one is required to use.
In addition, Visual Studio offers Secured Template Overload as a feature that is intended for C++ instead of C.
Setting _CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES
to 1
char A[10];
strcpy(A,B);
is compiled as strcpy_s(A,sizeofA,B);
so that you can provide a little more security with source code compatibility with environments that do not have strcpy_s
.
© 2024 OneMinuteCode. All rights reserved.