C语言结构体数组成员怎么赋值?

来源:百度知道 编辑:UC知道 时间:2024/06/30 01:32:36
要给stu[0].name赋值该怎么写啊?我这样写是错的。
typedef struct student
{int num;
char name[8];
}st;

void infor(st stu[N])
{stu[0].name="aa";
stu[1].name="bb";
...
}

给出一下代码,其中使用strcpy函数,头文件为#include<string.h>。
其用法为strcpy(字符数组,需要拷贝的字符串);
#include <iostream>
#include <cstring>
using namespace std;
struct stu
{
char name[8];
char snum[9];
}st[10];
int main()
{
strcpy(st[0].name,"sss");//在结构体中对字符型数组赋值通常是用strcpy函数
strcpy(st[0].snum,"alala");
cout<<st[0].name<<endl;
cout<<st[0].snum<<endl;
return 0;
}

strcpy(stu[0].name,"aa");