I've made the following changes to your code and it started working for me:
char Fname[];
-->char Fname[100];
char Lname[];
-->char Lname[100];
char sec;
-->int sec;
This is needed for scanf.scanf("%d",e->reg_no);
-->scanf("%d",&e->reg_no);
scanf("%d",e->Class);
-->scanf("%d",&e->Class);
scanf("%d",e->sec);
-->scanf("%d",&e->sec);
- adding
\n
to the end ofprintf
strings inDisplay
Please note that scanf("%s", ...)
is insecure and it can cause a crash the input string is longer than the array size you're reading it to, i.e. if the user types a name of at least 100 bytes.
Please note that you should always check the return value of scanf
, and abort early on error (i.e. if it doesn't return 1
in your case).
Please note that in C++ the istream
methods (http://en.cppreference.com/w/cpp/header/istream) provide a safer way to read the input.