鱼C论坛

 找回密码
 立即注册
查看: 2105|回复: 5

[已解决]C语言第一节课后习题运行不了

[复制链接]
发表于 2023-9-10 16:47:29 | 显示全部楼层    本楼为最佳答案   
这些错误是由于使用了不安全的函数而导致的。Visual Studio 2019建议使用更安全的替代函数。

你可以按照编译器的建议进行修改,使用更安全的函数代替。
对于`fopen`,你可以使用`fopen_s`来替代:

  1. if (fopen_s(&fp, filename, "r") != 0)
  2. {
  3.     fprintf(stderr, "Can not open the file:%s\n", filename);
  4.     return 0;
  5. }
复制代码



对于`strcpy`和`strcat`,你可以使用`strcpy_s`和`strcat_s`来替代:

  1. strcpy_s(thePath, MAX, path);
  2. strcat_s(thePath, MAX, "/*.c");

复制代码

对于`sprintf`,你可以使用`sprintf_s`来替代:

  1. sprintf_s(target, MAX, "%s/%s", path, fa.name);
复制代码


这样修改后,你的代码应该可以在Visual Studio 2019中编译通过了。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-23 07:31

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表