关于VS2022,C语言打开文件时的错误

关于VS2022 fopen_s函数错误

img

img

#include <stdio.h>
#include <stdlib.h>
//#define _CRT_SECURE_NO_WARNINGS
int main(void)
{
FILE* fp;
FILE *p;
int ch;

if ((fp = fopen_s("p", "text.txt","r")) == NULL)
{
    printf("打开文件失败!\n");
    exit(EXIT_FAILURE);
}

while ((ch = getc(fp)) != EOF)
{
    putchar(ch);
}

fclose(fp);

return 0;

}

在同级文件夹放了个文件,但打开后程序自动关闭

img

int fp
if ((fp = fopen_s(&p, "text.txt","r")) != 0)

fopen_s的参数和fopen是不一样的,仔细看看吧
https://blog.csdn.net/qq_45919489/article/details/104222423

fopen_s第一个参数错了吧?