首页 > 解决方案 > 在 VS2017 中使用 fread_s 出现问题

问题描述

我试图从文本文件中读取一组数字。我正在使用 Visual Studio 2017 - 我在使用fread_s(). 欢迎任何从文件中读取数字数组的方式。

#include "stdio.h"
#include "tchar.h"
#include "stdlib.h"

int main()
{
    FILE *fp;
    errno_t err_code;
    int i_i;
    int *arr_p;
    int ch[10];
    i_i = 0;
    arr_p = &ch[0];

    if ((err_code = fopen_s(&fp, "test.txt", "r")) != 0)
    {
        printf("File was not opened\n");
    }
    else
    {
        printf("%d :: %d ::%d \n", *arr_p, sizeof(ch), sizeof(int));
        // This line of code, should ideally read the first number in the file
        fread_s(arr_p, sizeof(ch), sizeof(int), 1, fp);
        fclose(fp);
    }
}

标签: cvisual-studio-2017

解决方案


推荐阅读