I am still very noob in c++, pardon me if there are terms I am misusing below.
I have two problems regarding calling arrays within functions:
1. I am having difficulties to call char arrays (as you will see below in the code)
2. I am trying to flesh out my code so I dont have monster function with 70 arguments. However I can find a to extract and print a value whitin an array without having to call the array as an argument. Is it possible to define an array globally and just print anything from it from a function without having to pass it as argument ?
#include <curses.h>
void some_function(int argumentA, int argumentB, int argumentD, char *item_array[10]);
//ARRAY PRINT THROUGH FUNCTION
int main ()
{
int argumentA, argumentB, argumentD;
char *item_array[10];
item_array[1]="apple";
some_function(argumentA, argumentB, argumentD, item_array[10]); //<-- 1st problem here, "cannot convert 'char' to 'char**' for argument 4"
getch();
}
//FUNCTIONS CODE
void some_function(int argumentA, int argumentB, int argumentD, char *item_array[10]){
printf(item_array[1]);
}
}
Also, assuming the code above works, I want to reach something like this:
include <curses.h>
void some_function(int argumentA, int argumentB, int argumentD);
//ARRAY PRINT THROUGH FUNCTION
int main ()
{
int argumentA, argumentB, argumentD;
char *item_array[10];
item_array[1]="apple";
some_function(argumentA, argumentB, argumentD); //<--only 3 arguments here.
getch();
}
//FUNCTIONS CODE
void some_function(int argumentA, int argumentB, int argumentD){
printf(item_array[1]);
}
item_array is an array of pointer to char, when you pass item_array[10] to the function, you are trying to pass the (unexisting) 11th element of that array
And in the second piece of code, move the definition of item_array[10] outside of the functions.
(i.e. write it right above main() or somewhere else as long as it is outside of a function and defined before it is used in a function)
Edit:
This post was not intended for the post above, you posted it while i was writing =P