Parameter overdrive.....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidKrutsko
    New Member
    • Aug 2007
    • 13

    Parameter overdrive.....

    Hey i have a rather wierd question....

    say i have a function that compares strings that looks like the following when used in code:

    Code:
    if ((StrComp (some char* here, another char* here)) [.......]
    1st param is 1st string and 2nd is what the 1st is being compared to..... if they are the same then true else false....

    now i have a group of strings i want to compare and i dont want to write like 7 of those if statmenets or keep repeating the function in that one if statements...

    i was wondering if there is a way to squeeze together a bunch of strings in the 2nd param in order to compare it and if any of them are true do something else do something else.... example:

    Code:
    if ((StrComp(CHARA, (CHARB OR CHARC OR CHARD OR etc...))
    instead of
    Code:
    if (StrComp (CHARA, CHARB) || StrComp (CHARA, CHARC)) ... etc.
    if tried #define groupA (CHARA, CHARB, etc...) but i get a runtime error

    P.S. is there a way to increase the number of parameters based on programmers input without actually modifying the code to include like 50 of them with default values?

    thanks

    DK--
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The customary way to do this is to have an array of strings as a function argument.

    There is an old C method that uses an ellipsis argument (...). Here you use the C va_arg macros but you will need another function argument to tell the number of strings. In this case your code would starft to look like that of
    printf().

    Comment

    Working...