| |

VerySource

 Forgot password?
 Register
Search
View: 1618|Reply: 2

Determine the number of variable parameters of a variable parameter function

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-29 13:40:02
| Show all posts |Read mode
As follows: a variable parameter function,
       variable is the number of parameters of the variable parameters that I know in advance (taken from the database)
        void add_Log_Msg (int log_msg_macro, int uid, char * sn, ...)
       {
         va_start (vp, sn);
variable = spLogsMsg-> variableNum;
if (variable> 0)
{
for (i = 0; i <variable; i ++)
{
s_varible_value [i] = va_arg (vp, char *);
}
}
va_end (vp);
         ...
       }
     I decided to take a few variable parameters according to the variable.
Because the program does not know it will still fetch it, but this parameter does not exist, causing the program to crash.
How to solve this problem?
Reply

Use magic Report

0

Threads

5

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-5-3 17:30:01
| Show all posts
Unable to solve, must pass the correct parameters
There is no need to use variable parameters, it is also convenient to pass the parameters into a string with the specified separator
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-30 13:15:01
| Show all posts
Use terminator, find a special value as terminator,
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list