How to use malloc to allocate memory instead for char name[50];
I don't know these concepts am new for c
.
struct student
{
char name[50];
int roll;
float marks;
};
int main()
{
int c;
printf("no. of students\n");
scanf("%d",&c);
struct student *s;
s=(struct student *) malloc (sizeof(struct student));
int i;
printf("\nstudents information:\n");
for(i=0;i<c;++i)
{
printf("enter the name:");
scanf("%s",s[i].name);
printf("enter roll no:");
scanf("%d",&s[i].roll);
printf("enter the marks:");
scanf("%f",&s[i].marks);
printf("\n");
}
printf("\ndetails of all the student:\n");
for(i=0;i<c;++i)
{
printf("the student name:%s\n",s[i].name);
printf("the student roll no. is:%d\n",s[i].roll);
printf("the student mark is:%.2f\n",s[i].marks);
printf("\n");
}
return 0;
}