I just need to know how to pass and declare a FILE*
array into a function
void openInputFiles(char* name, FILE* input[]){
char filename[10];
if (strcmp("average", name) == 0){
int i;
int k =1;
for (i=1;i<=10;i++){
if (i<10){
sprintf(filename,"%s_00%d",name,k);
}
if (i == 10){
sprintf(filename,"%s_0%d",name,k);
}
input[i-1] = fopen(filename,"r");
k++;
}
}
if (strcmp("median", name) == 0){
int i,k;
k=1;
for (i=1;i<10;i++){
sprintf(filename,"%s_00%d",name,k);
input[i-1] = fopen(filename,"r");
k++;
}
}
}
That's the code for the function and this is where I am trying to call it
int main(int argc, char* argv[]){
FILE* input[10];
openInputFiles(argv[1],input);
}
I don't get any warnings when I compile this but when I try to gdb it to test what's wrong it's seeming that the FILE*
isn't allocating a memory address to input[0]
because it says its at address 0x0
. What am I doing wrong?