Why we can't use arrow operator in gets and puts?

C++Server Side ProgrammingProgramming

You can't read user input in an un-initialized pointer. Instead, have a variable of the struct data type and assign its address to pointer before accessing its inner elements by → operator

example

#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);
}

Output

Typical result of above code

enter name Disha
You entered Disha
raja
Published on 08-May-2018 15:09:20
Advertisements