我正在尝试从文本文件中读取数字数组。我正在使用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);
}
}