This is an Example of Runtime Memory allocation using MALLOC() & CALLOC() STRCTURE
#include #include #include #include
struct student { char nm[10]; int m1; int m2; int m3; int total; };
void main() { int n,i; struct student *p; clrscr(); printf(" Enter variables "); scanf("%d",&n); p=(struct student *)calloc(n,sizeof(struct student)); if(p==NULL) { printf(" Not Sufficient Memory "); getch(); exit(0); } for(i=0;i { printf("\n \n \t Enter Name M1 M2 M3 "); scanf("%s%d%d%d",(p+i)->nm,&(p+i)->m1,&(p+i)->m2,&(p+i)->m3);
(p+i)->total=(p+i)->m1+(p+i)->m2+(p+i)->m3; }
for(i=0;i { printf(" \n \n \t NAME %s Total %d \n ",(p+i)->nm,(p+i)->total); } getch();
}
|
No feedbacks found. Be the first to respond and make money from revenue sharing program.
|