您无法在未初始化的指针中读取用户输入。而是使用struct数据类型的变量并将其地址分配给指针,然后再通过→运算符访问其内部元素
#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