I usually deal with array of strings this way, because it allow me to not specify a character limit :
char *names[2] = {"John","Doe"};
printf("%s\n",*((names)));
printf("%s\n",*((names)+1));
I am unable to reproduce this while using a struct.
I tried with both john.names = {"John","Doe"}; and john.*names = {"John","Doe"}. But I am getting an expected expression error.
However, I am able to do so during the initialization with Person john = {{"John","Doe"}};. So I'm not sure if it's allowed to proceed like this only during initialization.
main.h
typedef struct Person Person;
struct Person
{
char *names[2];
};
main.c
#include <stdio.h>
#include <stdlib.h>
#include "main.h"
int main()
{
Person john = {{"John","Doe"}};
john.names = {"John","Doe"}; // Expected expression error
printf("%s\n",john.names[0]);
printf("%s\n",john.names[1]);
return 0;
}
What would be the "expected expression", am I allowed to do this ?
printfjust before myreturn 0. But what I would like is being able to use brackets.