为什么我们不能在 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
广告