- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Why we can't use arrow operator in gets and puts?
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
Advertisements