I am trying to pass the address of strings_line_tokens to split_string. I would think I would need the "&" for the address then one of these methods would work.

static void split_string(const char *buffer, size_t buflen, char ***strings_line_tokens)
static void split_string(const char *buffer, size_t buflen, char **strings_line_tokens)
static void split_string(const char *buffer, size_t buflen, char **strings_line_tokens[])
static void split_string(const char *buffer, size_t buflen, char ***strings_line_tokens[])

Here is my declaration and where I try to pass the address to the function.

char *strings_line_tokens[503] = {0};
split_string(line, strlen(line)+1, &strings_line_tokens);

I keep getting some variation of this error.

warning: passing argument 3 of ‘split_string’ from incompatible pointer type
main.c:73: note: expected ‘char **’ but argument is of type ‘char * ()[503]’

The array to pointer conversion you're probably familiar with only applies to the first dimension of an array. The only solution here is to dynamically allocate the strings as well such that you originally have a char**:

char **strings_like_tokens = malloc(503 * sizeof *strings_like_tokens);

...

split_string(line, strlen(line) + 1, strings_like_tokens);

char** and char*[503] are not compatible types.

However, since this is clearly C++ (C does not support function overloading), good God please use std::vector<std::string>. You'll thank me for the time saved managing memory. :D

Try split_string(line, strlen(line)+1, &strings_line_tokens[0]);

@deceptikon I'm using C not C++ :(.

@deceptikon I'm using C not C++ :(.

Sorry to disappoint, but you're not. C does not allow multiple functions with the same name, overloading is not a feature current or planned for C. If you're allowed to create overloaded functions, you're actually compiling your code as C++, even if for the most part it looks like C.

Or you're depending on a compiler extension, in which case it's technically neither C nor C++. ;)

However, if you want to keep pretending, then the correct solution is as I stated before. rubberman's suggestion will also work in this specific case, but given the declaration for your other overloads I'd hazard a guess that you also want functionality which this trick isn't safe for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.