I'm populating a C program to multiply 2 input vectors. Here is the code:
/**
* Function name: parseArguments
* Description:
* Determine what options or arguments user used
* Command-line options:
* [-h] : Show help information
* [-n] num: Determine number of threads
* file1 : Choose first file
* file2 : Choose second file
* Return value:
* 0: If parsing successful
* exit: If error
**/
static int parseArguments(int argc, char **argv, int* nthreads, char* file1, char* file2)
{
int opt;
int help=0;
extern int optind;
extern char * optarg; // (global variable) command-line options
while ((opt = getopt(argc, argv, "hn:")) != EOF)
{
switch (opt) {
//Parse option -h, -n
case 'n':
*nthreads = atoi(optarg);
break;
case 'h':
Usage();
exit(1);
break;
default:
fprintf(stderr, "Try 'mulvector -h' for more information\n");
exit(1);
}
// parse file1 & file2 arguments
// THIS IS WHAT I'M ASKING
if (optind < argc)
{
file1 = &argv[optind];
optind++;
}
if (optind < argc)
file2 = &argv[optind];
}
return 0;
}
The problem is that, after i called this function (in the main() function) and then exit this function (continue the main() function), the 2 variables file1 & file2 still keep their old values before executing the parseArguments function. I'm trying to fix this but i get no result ...
Hope you guys can help, thanks so much in advanced !
NOTE: The type of file1 and file2 are char file1[1024] so i can't use char** as the arguments for the parseArguments function !