I am trying to learn structures and the below code is having some sort of error, not logical but just shows up while execution saying, the file has stopped working. Occurs right after gets(s2.name)
#include<stdio.h>
struct student
{
char *name;
float mark1,mark2,mark3;
float total;
};
int main()
{
struct student s1,s2,s[3];
s1.mark1=6;s1.mark2=7;s1.mark3=8;
s1.total = s1.mark1+s1.mark2+s1.mark3;
printf("\nEnter the name of s2 : ");
gets(s2.name);
/*when above line is inserted program hangs and code below does not execute*/
puts(s2.name);
s1.name = "shanky";
puts(s1.name);
getch();
return 0;
}
No compilation error obviously. Using gcc compiler