Is there a shorthand for this multidimensional array declaration in C -


so have code:

#include <stdio.h> #include <stdlib.h> #include <string.h> char field1[45]; char field2[444]; char *fields[] = {     field1, field2 }; int main (int argc, char *argv[]) {     sprintf(fields[0], "hello\n");     printf(fields[0]); } 

i have no need accessing fields using field1 , field2. there shorthand way this? tried following doesn't work.

char *fields[] = { char[45], char[444] }; 

basically guess want array contains character strings of varying length without having use malloc.

you write:

char *fields[] = {     (char[45]) { 0 },     (char[444]) { 0 } }; 

i'd suggest against using design though makes difficult perform check won't overrunning buffer.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -