struct node{
char a[100];
struct node* next;
};
typedef struct node* nodeptr;
main()
{
char b[100];
nodeptr p;
int n;
printf("enter the string\n");
scanf("%s",b);
n=strlen(b);
p=getnode();
p->a=b;
p->next=null;
printf("%s \n",(q->a));
return 0;
}
How can I access the array inside the struct using a struct pointer? Is this the correct method? I am getting the following error during compilation:
incompatible types when assigning to type ‘char[100]’ from type ‘char *’ "
Your code at
p->a=bis simply not allowed as a is an array and not a pointer and you are trying to copy a pointer to an array. Trystrncpy(p->a, b, 100)(of course you should have 100 as a#define)