1、定义结构体
结构体像子函数一样,在int mian()外定义
①定义结构
struct Mp3Song(结构体名称)
{
char singer[32]; // 歌手名字
char title[128]; // 歌名
int hits; // 下载量
}
②main中结构体的调用
int main()
{
struct Mp3Song mp3;
strcpy_s(mp3.title, 128, "起风了");
strcpy_s(mp3.singer, 32, "大神慧");
mp3.hits = 1293940;
printf("歌手: %s \n", mp3.singer);
printf("歌名: %s \n", mp3.title);
printf("点击量: %d \n", mp3.hits);
return 0;
}
结构体的重命名
使用strcpy函数进行重新赋值,主要是下面两种情况:
字符串赋值:第一个参数为结构体中的元素(重命名名称.元素名称),第二个参数为定义数组的长度,第三个参数为赋值的内容
整数赋值:重命名名称.元素名称=赋值内容