I am trying to assign 3 names to a string vector within a struct, and using pointers to reference the dynamically allocated struct, and then print and reverse it in a repeat structure, but when trying to print it it is not returned nothing.
String to be printed
printf("%s\n",*(*p).vet[1]); Ana
printf("%s\n",*(*p).vet[2]); Bia
printf("%s\n",*(*p).vet[3]); Lia
Inverted String
printf("%c\n",*(*q).vet[1]); a+n+A
printf("%c\n",*(*q).vet[2]); a+i+B
printf("%c\n",*(*q).vet[3]); a+i+L
Code
#include<stdio.h>
#include<stdlib.h>
typedef struct elemento *ponteiro;
struct elemento
{
int chave;
char vet[100][4];
ponteiro prox;
};
main()
{
ponteiro p,prim,h,q;
int i;
prim=NULL;
p=(ponteiro) malloc(4*sizeof(struct elemento));
h=p;
(*p).chave=1;
*(*p).vet[1]="Ana";
*(*p).vet[2]="Bia";
*(*p).vet[3]="Lia";
printf("%s\n",*(*p).vet[1]);
printf("%s\n",*(*p).vet[2]);
printf("%s\n",*(*p).vet[3]);
for(i=0;i<3;i++)
{
q=(ponteiro)malloc(sizeof(struct elemento));
*(*q).vet[1]=*(*p).vet[1]+*(*p).vet[1,4-i];
*(*q).vet[2]=*(*p).vet[2]+*(*p).vet[2,4-i];
*(*q).vet[3]=*(*p).vet[3]+*(*p).vet[3,4-i];
printf("%c\n",*(*q).vet[1]);
printf("%c\n",*(*q).vet[2]);
printf("%c\n",*(*q).vet[3]);
p=q;
}
}