How to create variadic macro (accept variable number of arguments) to run the printf function in C

1 Answer

0 votes
#include <stdio.h>

#define LOG(format, ...) printf(format, __VA_ARGS__)

int main(void) {
    LOG("%d\n", 3);

    LOG("%d %s %f\n", 9801, "c programmming", 3.14);

    int n = 7187;
    char str[] = "r2d2";
    char ch = 'z';
    float f = 382.59;

    LOG("%d %s %c %f\n", n, str, ch, f);
}




/*
compile:

3
9801 c programmming 3.140000
7187 r2d2 z 382.589996

*/

 



answered Apr 28, 2022 by avibootz

Related questions

...