you must not put such stuff in headers;
header:
enum { CONNECTIONS_AMOUNT=2 };
extern const char *DB[CONNECTIONS_AMOUNT];
extern const char *USERNAME[CONNECTIONS_AMOUNT];
enum { CONNECTIONS_AMOUNT=2 };
extern const char *DB[CONNECTIONS_AMOUNT];
extern const char *USERNAME[CONNECTIONS_AMOUNT];
To copy to clipboard, switch view to plain text mode
.c-file
const char *DB[CONNECTIONS_AMOUNT] = {"db1","db2"};
const char *USERNAME[CONNECTIONS_AMOUNT] = {"root1","root2"};
const char *PASSWORD[CONNECTIONS_AMOUNT] = {"admin","admin"};
const char *DB[CONNECTIONS_AMOUNT] = {"db1","db2"};
const char *USERNAME[CONNECTIONS_AMOUNT] = {"root1","root2"};
const char *PASSWORD[CONNECTIONS_AMOUNT] = {"admin","admin"};
To copy to clipboard, switch view to plain text mode
otherwise you get one instance per file where the .h file is included - unless the linker can sort out the duplicates.
To your question:
you defined a big "rectangle" of x*y bytes.
I define a vector of pointers to strings.
This is not the same (in memory), but if you actually want an array of strings, perhaps closer to your intentions.
Also, note that
const char PASSWORD[CONNECTIONS_AMOUNT][MAX_STRING_SIZE]
const char PASSWORD[CONNECTIONS_AMOUNT][MAX_STRING_SIZE]
To copy to clipboard, switch view to plain text mode
allocates CONNECTIONS_AMOUNT * MAX_STRING_SIZE bytes.
My code "allocates" (needs) CONNECTIONS_AMOUNT * sizeof(pointer) + the actually needed string sizes.
Finally, your code could allow the strings to be modified (without const), mine cannot, as "somestring" is of type const char*.
HTH
Bookmarks