我是学习结构的初学者。我的代码有点问题。我知道这不是分配字符串的方法。有人可以告诉我怎么做吗?该网站教我这样做。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_PERSON 50
#define NAME_LENGTH 30
#define ADDR_LENGTH 60
struct player {
char name [NAME_LENGTH];
char address [ADDR_LENGTH];
int salary;
};
int main (int argc, char *argv[]){
struct player singleTeams;
struct player multipleTeams[MAX_PERSON];
singleTeams.name = "David";
multipleTeams[20].name = "Robin";
printf("Person on the single team is %s\n", singleTeams.name);
printf("Person on the multiple team is %s\n", multipleTeams[20].name);
return EXIT_SUCCESS;
}
我的错误在这条线上
singleTeams.name = "David";
multipleTeams[20].name = "Robin";