Hi there,
I'm trying to pass in an array of strings to a function and am obviously having trouble with the basic idea behind storing strings to an array of strings.
I have a prototype something like this:
Code:
char **read_files(const char *files[], size_t nfiles, size_t *nlines)
That takes an array of file names, opens them, reads them all ,and stores them to a dynamically allocated array. But right now I can't even pass in the array of filenames.
In my main, I'm trying to just parse the input file names from the command line, store them to my files[] array and handle them inside the above function.
So right now I can parse everything and get a single filename, but need to get it into an array.
Code:
int main(int argc, char *argv[]) {
FILE *fp;
int option = 0;
char *filename;
size_t nlines;
size_t nfiles;
int j;
/* omiting code for parsing options, that is working */
for(j = i; j < argc; j++)
{
filename = argv[j];
nfiles++;
printf("%s", filename[j]);
}
read_files(files, nfiles, size_t *nlines);
return 0;
}
I'm just wondering what the best approach would be to store the filename to an array of filenames and pass them to the function?