Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5145

C/C++ • Re: Two-dimensional array of character strings in C

$
0
0
You'll need to use the va_copy macro and use the variants of printf that are prefixed with a "v" (e.g. vsnprintf).
See https://en.cppreference.com/w/c/io/vfprintf#Example for an example.

Thanks works a treat added the following function

Code:

void gprintf(const char *fmt, ...){    va_list args1;    va_start(args1, fmt);    va_list args2;    va_copy(args2, args1);    char buf[1+vsnprintf(NULL, 0, fmt, args1)];    va_end(args1);    vsnprintf(buf, sizeof buf, fmt, args2);    va_end(args2);    printf("%s",buf);    fprintf(file,"%s",buf);}
and called like this

Code:

gprintf("\n  Data %s  next data  %s ",data[3] [0],data[3] [1]);  // access datagprintf("\n  Data %s  - \n",data[0] [0]);  // access data

Statistics: Posted by Geralds — Mon Feb 05, 2024 8:00 pm



Viewing all articles
Browse latest Browse all 5145

Trending Articles