I'm trying to extract the data from a file and store it directly in an array from the fread function. However, it seem like the data type is incorrect?
Here is the error message:
dataPlus.c:28:15: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'void *' [-Werror,-Wint-conversion] fread(ptr[i], 1, 1, in);
How can I make those data accessible? For instance, if I want to check if the first 3 char in the text files are 1, 2, and 3.
/**
* To store specific lines of data from fread into array.
* Alternatively, to make the buffer recieved from fread, readible
**/
#include <stdio.h>
int main(void)
{
FILE* in = fopen("in.txt", "r");
if (in == NULL)
{
printf("File does not exist.\n");
return 1;
}
FILE* out = fopen("out.txt", "w");
//read file information into array.
int ptr[4];
//error here... Tried to store it directly into array instead of buffer..
for(int i = 0; i < 4; i++)
{
fread(ptr[i], 1, 1, in);
}
for(int j = 0; j < 4; j++)
{
printf("success. Array[%i] is --> %i value\n", j, ptr[j]);
}
fclose(in);
fclose(out);
}