Home > Back-end >  C language variable parameter error
C language variable parameter error

Time:02-19

Error phenomenon:
Calling print (" aaaaa ", "22222", "333333"); Error, screenshot below

Calling print (" BBBBB ", "44444", "5555555", "666666"); The output is normal
 
The book @ 100 ask:/MNT/HGFS/Linux/linux_base $./multiapp
44444... 5555555... 666666...

The code is as follows:
 

Excuse me, how to solve,
#include
#include
#include
#include
Int print (const char * format,... )
{
Va_list args.
Const char * args1;
Va_start (args, format);
While (1)
{
Args1=va_arg (args, const char *);
If (strlen (args1))
Printf (" % s... ", args1);
The else
break;
}
Va_end (args);
printf("\n");
return 0;
}
Int main ()
{
Print (" aaaaa ", "22222", "333333");
//print (" BBBBB ", "44444", "5555555", "666666");
return 0;
}

CodePudding user response:

 # include & lt; stdio.h> 
#include
#include
#include

Int print (const char * format,... )
{
Va_list args.
Const char * args1;
Va_start (args, format);

//printf (" % s... ", the format);
While (1)
{
Args1=va_arg (args, const char *);
If (args1==NULL)
break;
Printf (" % s... ", args1);
/*
If (strlen (args1))
Printf (" % s... ", args1);
The else
break;
*/
}
Va_end (args);
printf("\n");
return 0;
}
Int main ()
{
Print (" aaaaa ", "22222", "333333", NULL);
//print (" BBBBB ", "44444", "5555555", "666666");
return 0;
}

For your reference ~

Lack of end logo

CodePudding user response:

Main function:
 int main () 
{
Print (" aaaaa ", "22222", "333333", "");//string length 0
Print (" BBBBB ", "44444", "5555555", "666666", "");
return 0;
}
  • Related