I'm familiar with the concept of int in the for loop. However, I've seen a case where the condition for the for loop is a pointer. How is the pointer used or interpreted in the for loop condition in C or C++. As an example:
Code:
void printer(char *fmt, ...) {
va_list args;
char *p, *sval;
int ival;
double dval;
va_start(args, fmt);
for(p = fmt; *p; p++) {
if(*p != '%') {
putchar(*p);
continue;
}
switch(*++p) {
case 'd':
ival = va_arg(args, int);
printf("%d", ival);
break;
case 'f':
dval = va_arg(args, double);
printf("%.2f", dval);
break;
case 's':
for(sval = va_arg(args, char*); *sval; sval++)
putchar(*sval);
break;
default:
putchar(*p);
}
}
va_end(args); // cleanup when done
}
This example is derived from the book:
The C programming Language
By Brian W. Kernighan and Dennis M. Ritchie.
Published by Prentice-Hall in 1988
ISBN 0-13-110362-8 (paperback)
ISBN 0-13-110370-9