I am struggling to pass an array of files as an argument to pthread_create function.
FILE *arqvs[arq];
for(int i=1, count=0;i<=arq;i++, count++){
changeName(file, i); //change the name of the file based on the index
arqvs[count] = fopen(file, "r");
if(arqvs[count]==NULL){
printf("Erroro:(\n");
exit(1);
}
}
The code above shows how I am creating the array and opening the files in "r" mode. I have done some tests and it seems to work well. Is reads all the files based on the number of the variable arq. The problem comes out when I try to pass the array to the function pthread_create as mentioned above..
Here's the code:
for(int i=0;i<trd; i++){
pthread_create(&thread[i], NULL, funcao, &**arqvs);
}
And here's the function:
void * funcao(void * args){
char voto[2];
FILE *** fileName = (FILE***) args;
while (fgets(voto, sizeof(voto), *fileName[0])) {
printf("%s", voto);
pthread_exit(NULL);
}
This code does not work, and I dont know why. It has been awhile since I programmed in C, so, I would appreciate any hints or answers.