I'm having trouble working with strings in C. Excuse the informality, I'm usually on Math Stackexchange. Here is my function which takes an array of strings and returns a randomly selected one. randint(int n) is a function which returns a random integer from 1 to n.
int rand_word(const char ARR[]) {
int r = randint(sizeof(ARR));
return(ARR[r]);
}
Here is my main():
int main() {
const char *WORDS[3];
WORDS[0] = "a";
WORDS[1] = "b";
WORDS[2] = "c";
printf("%s", rand_word(WORDS));
return 0;
}
I expected to see either "a", "b", or "c" printed.
[Error] cannot convert 'const char**' to 'const char*' for argument '1' to 'int rand_word(const char*)'
Essentially my confusion is between data types. What have I done wrong? Thanks.