G
Guest
void show( char *s, ...) is a function seemd like prinf
code
--------------
#include <stdio.h>
#include <stdarg.h>
void show( char *s, ...)
{
va_list stage;
char *ps;
char pchar;
int pint;
double pdouble;
float pfloat;
va_start( stage, s);
{
while (*s)
{
switch (*s)
{
case '%':
{
s++;
switch (*s)
{
case 'f':
case 'F':
pdouble = va_arg(stage, float );
printf("%f", pdouble);
break;
case 'd':
case 'D':
pint = va_arg(stage, int );
printf("%d", pint);
break;
case 's':
case 'S':
ps = va_arg(stage, char* );
printf("%s", ps);
break;
case 'c':
case 'C':
pchar = va_arg(stage, char );
printf("%c", pchar);
break;
}
s++;
break;
}
default:
printf("%c",*s);
s++;
break;
}
}
}
}
int main()
{
int x =55;
char h ='a';
show("%c",h);
show("%c",h);
return 0;
}
---------------------------------------
under vc6.0 it can run well!
but under linux redhat7.x gcc error! win2k +dev c++ 4.98
errow !
case 'c':
case 'C':
pchar = va_arg(stage, char ); // here!!!
printf("%c", pchar);
break;
how to fix
code
--------------
#include <stdio.h>
#include <stdarg.h>
void show( char *s, ...)
{
va_list stage;
char *ps;
char pchar;
int pint;
double pdouble;
float pfloat;
va_start( stage, s);
{
while (*s)
{
switch (*s)
{
case '%':
{
s++;
switch (*s)
{
case 'f':
case 'F':
pdouble = va_arg(stage, float );
printf("%f", pdouble);
break;
case 'd':
case 'D':
pint = va_arg(stage, int );
printf("%d", pint);
break;
case 's':
case 'S':
ps = va_arg(stage, char* );
printf("%s", ps);
break;
case 'c':
case 'C':
pchar = va_arg(stage, char );
printf("%c", pchar);
break;
}
s++;
break;
}
default:
printf("%c",*s);
s++;
break;
}
}
}
}
int main()
{
int x =55;
char h ='a';
show("%c",h);
show("%c",h);
return 0;
}
---------------------------------------
under vc6.0 it can run well!
but under linux redhat7.x gcc error! win2k +dev c++ 4.98
errow !
case 'c':
case 'C':
pchar = va_arg(stage, char ); // here!!!
printf("%c", pchar);
break;
how to fix