I'm trying to read a file and fill an array with all the characters in the file. The problem is that in the while cycle the execution stops and there is a segmentation fault error. This is the interested function:
void allocAndFillArray(char **arrayChar, FILE *file) {
// *file is checked before the function and
// if the function is called the pointer is not NULL
int len = x; // x is just a random size. In the real function it is the number of characters in the file
*arrayChar = (char *)calloc(len, sizeof(char));
int i = 0;
while (i < len) {
*arrayChar[i] = fgetc(file);
i = i + 1;
} // in this cycle the execution stops after the first iteration
// and only one character is written in the array
// before a crash reported as segmentation fault.
fclose(file);
}
I tried changing calloc with malloc, tried changing the size but it just doesn't work