无法使用c中的结构设置名称(字符数组)

Unable to set name(character array) using structure in c

struct Student {
char name[10];
};


void set(struct student *s,const char *n)
{
s->name=n;    // this line is showing error(incompatible types in assignment)
}


int main()
{
struct Student stud;
char name[]="abc";
set(&stud,name);
}

这一行

s->name=n;

显示不兼容赋值的编译时错误。 如何将使用函数传递的名称分配给结构变量。

你需要使用strcpy来复制字符串,所以

strcpy(s->name,n); 

并改变

void set(struct student *s,const char *n)

void set(struct Student *s,const char *n)
                ^
                capital S

s->name是一个数组,它不能是=的左操作数。请改用 strcpy