user2844391
user2844391

Reputation: 9

concatenating arrays of strings using macro

I need to concatenate two arrays of string and need to call the function with that string

I have two arrays

char q[4] = {'t','e','s','t'};
char w[4] = {'f','u','n','c'};

#define dump(a,b)  a ## b

I have a function called

void testfunc()
{

...
..

}

if I call the macro dumb like dumb(q,w) this is just concatenating q and w, i need to concatenate the strings in that array.

Need to call the function by concatenating the arrays of string using macros. Is that possible??

Upvotes: 0

Views: 169

Answers (2)

jev
jev

Reputation: 2013

I just want to call the function testfunc() which name is stored in two array char

Although you can't use macros in this case you could have an array for function pointers and select one you want to call at run time.

void (*p[NFUNCS])(void);
//...
p[0] = testfunc; /* store address of the function */
//...
(*p[0])(); // call to testfunc

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272537

No. Macros don't understand C constructs (such as arrays), they just perform simple text substitution.

Upvotes: 4

Related Questions