P194. WAP to allocate dynamic memory to 5 students database, scan it and print it.
#include<stdio.h>
#include<stdlib.h>
struct
st
{
int roll;
char name[20];
float marks;
};
void
main()
{
int num,i;
struct st *p[5];
for(i=0;i<5;i++)
p[i]=malloc(sizeof(struct st));
for(i=0;i<5;i++)
{
printf("Enter roll
number\n");
scanf("%d",&p[i]->roll);
printf("Enter name
number\n");
scanf("%s",p[i]->name);
printf("Enter total
marks\n");
scanf("%f",&p[i]->marks);
}
for(i=0;i<5;i++)
printf("%d %s %f\n",
p[i]->roll,p[i]->name,p[i]->marks);
for(i=0;i<5;i++)
{
free(p[i]);
p[i]=0;
}
}
Comments
Post a Comment