我是學習結構的初學者。我的代碼有點問題。我知道這不是分配字符串的方式。有人可以告訴我如何?網站教我如此做。將變量賦值給字符串
#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";
代碼是純C語言,我不認爲C++會有所幫助。 – jnovacho
正如你所看到的那個人用C++標記了這個問題。 – Aravind