為什麼我們不能在 gets 和 puts 中使用箭頭運算子?
您無法在未初始化的指標中讀取使用者輸入。而應有一個結構資料型別的變數,並在使用 → 運運算元存取其內部元素之前,將其位址指定給指標
範例
#include <stdio.h> struct example{ char name[20]; }; main(){ struct example *ptr; struct example e; puts("enter name"); gets(e.name); ptr=&e; puts(ptr->name); }
輸出
上述程式碼的典型結果
enter name Disha You entered Disha
廣告