【发布时间】:2021-02-08 23:49:34
【问题描述】:
我在 Code::Blocks IDE 中运行了以下 C 代码,它可以正常工作,没有问题。我尝试在 Visual Studio 2015 中编译此代码,但出现此错误:
'strcpy_s': too few arguments for call
如何通过对我的代码进行最少的更改来解决此问题?代码如下:
#include<conio.h>
#include<stdio.h>
#include<string.h>
int main() {
char string[81];
int position;
printf("type a string :");
gets(string);
printf("enter position for delete character :");
scanf_s("%d",&position);
strcpy_s(&string[position], &string[position + 1]);
printf("the result string is: ");
puts(string);
_getch();
return 0;
}
Code::Clocks 可以运行此代码并为我提供正确的输出,但 Visual Studio 不能!我能做什么?
【问题讨论】:
-
关于
gets()的两点 a) 如果您将其与scanfX()函数混合使用,您可能会遇到问题,并且b) 请阅读Why is the gets function so dangerous that it should not be used? 它已过时。 -
感谢@WeatherVane,这行得通??
标签: c visual-studio visual-studio-2015 strcpy