在我的頭,我有:如何訪問指向結構的指針中的成員?
#define MAXSTRSIZE 20
struct Account{
char* Name;
char* Password;
};
,並在我的主要功能我:
struct Account* const AccountList=malloc(sizeof(struct Account)*AccountAmount)//AccountAmount is just an int value input by the user
FILE* File = fopen(FileName,"r");
int Counter;//Counter for the For Loop
for (Counter=0;Counter<AccountAmount;Counter++)
{
*(AccountList+Counter).Name=malloc(sizeof(char)*MAXSTRSIZE);
*(AccountList+Counter).Password=malloc(sizeof(char)*MAXSTRSIZE);
fscanf(File,"%s%s",*(AccountList+Counter).Name,*(AccountList+Counter).Password);
我編譯時出現以下錯誤「錯誤:請求成員‘名稱’的東西不結構或聯合「。我如何真正用包含成員的結構填充我分配的空間?
你也可以寫(*(AccountList + Counter))。Name ...但爲了可讀性使用AccountList [Counter] .Name ... – Byte