Hmmm...okay I just noticed this seems to work very nicely, it's only slightly more limited but it still saves a lot of potential malloc and strcpy. I suppose it is the same as just using char[][12] except I can use actual pointers in testfunc() (rather than a local copy):
Code:
#include <stdio.h>
#include <string.h>
typedef struct {
char X[256];
} string;
void testfunc(string *ray) {
printf("%s\n",(char*)&ray[2]);
strcpy((char*)&ray[3],"well done");
}
int main () {
string ray[4]={"this and that","more and","hello world"};
testfunc(ray);
printf("%s\n",(char*)&ray[3]);
return 0;
}
You actually don't even need the (char*) casts. The only issue seems to be that -Wall claims:
Code:
test2.c: In function ‘main’:
test2.c:14: warning: missing braces around initializer
test2.c:14: warning: (near initialization for ‘ray[0]’)
Is this significant and can I get out of it?