0

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??

6
  • testfunc doesn't appear to take any arguments?! Commented Oct 3, 2013 at 21:17
  • Those aren't strings. Strings (in C) are NULL-terminated, meaning the last character will be '\0', which you did not include. Commented Oct 3, 2013 at 21:18
  • do you want to use macros to expand to differnt function names? maybe you could use function pointers instead? Commented Oct 3, 2013 at 21:21
  • I just want to concatenate arrays of char. Commented Oct 3, 2013 at 21:23
  • why do you want to use a macro? Commented Oct 3, 2013 at 21:26

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.