簡體   English   中英

“)期望在第 7 行”傳遞結構數據時在 c 程序中出錯

[英]") expect on line 7" Error in c program when passing structure's data

幫幫我,我在 C 程序中得到“)預期在第 7 行和第 8 行錯誤”

代碼:

typedef struct {
    int rollnum;
    char name[20];
    char pass[20];
}student;

void updateName(student s1.name); //Getting error here
void updatePass(student s1.pass); // and here
// and all other functions like these

int main()
{
    //Some code here....
    return 0;
}

你的函數參數是錯誤的,基本上是錯誤的語法。 他們應該是

void updateName(char *name); 
void updatePass(char *pass);

您可能還想將指針傳遞給更新后的學生結構,因此您將聲明兩個參數,例如

void updateName(student*stud, char*name);

rollnum,name,pass 都是函數的不同參數,函數復制你在其作用域中傳遞的任何參數,然后執行

所以你可以使用指向變量的指針作為函數參數來解決這個問題(參見 FUNCTION CALL BY REFERANCE)或者只在一個參數中傳遞一個變量

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM