首页 > 解决方案 > “函数调用中的参数太少”(Visual Studio)。我无法打开文件。如何解决这个问题?

问题描述

“函数调用中的参数太少”(Visual Studio)。我无法打开文件。如何解决这个问题?

#include <stdio.h>

int main() {
    FILE * fp;
    fp = fopen_s("testfile.txt", "w"); //to open file
    return 0;
}

标签: c

解决方案


Too few arguments in function call意味着您调用了一个fopen_s带有 2 个参数的函数(在这种情况下),但该函数需要 3 个参数。

怎么解决?只需搜索并阅读. fopen_s()通常,也有使用示例。

阅读文档后,您会发现这是您的使用方式fopen_s()

int main(void) {
  FILE* fp = NULL;

  if (fopen_s(&fp, "testfile.txt", "w") != 0 || fp == NULL) {
    printf("ERROR: cannot open file\n");
    return EXIT_FAILURE;
  }

  ...
}

推荐阅读