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;
}
如何使用结构指针访问结构内的数组?这是正确的方法吗?我在编译期间收到以下错误:
从类型“char *”分配给类型“char[100]”时类型不兼容 "
最佳答案
您在 p->a=b
处的代码根本不允许,因为 a 是数组而不是指针,并且您正试图将指针复制到数组。试试 strncpy(p->a, b, 100)
(当然你应该有 100 作为 #define
)
关于c - 如何使用结构指针访问结构内部的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8671303/