DYNAMICS STRUCTURE





#include
#include
struct book{
int p;
char name[20];
char author[20];
};
int main()
struct book *s,*r;
int i,n;
printf("enter the size of structure\ndynamically structure\n");
scanf("%d",&n);
s=(struct book *)malloc(n*sizeof(struct book));
for(i=0;i<=n-1;i++)
{ scanf("%d",&(s+i)->p);//address uses for integer in structure
  fflush(stdin);
  gets((s+i)->name);// not address uses in gets function so not given
  fflush(stdin);
  gets((s+i)->author);
}
for(i=0;i<=n-1;i++)
{ printf("%d\n",(s+i)->p);/*value of integer is accessible without using *
  Because p is not address*/
   printf("%s\n",(s+i)->name);
   printf("%s",(s+i)->author);
   }
r=(struct book*)realloc(s,2*n*sizeof(struct book));
for(i=0;i<=2*(n);i++)
{ scanf("%d",&(s+i)->p);//address uses for integer in structure
  fflush(stdin);
  gets((s+i)->name);// not address uses in gets function so not given
  fflush(stdin);
  gets((s+i)->author);
}
for(i=0;i<=2*(n);i++)
{ printf("%d\n",(s+i)->p);/*value of integer is accessible without using *
  Because p is not address*/
   printf("%s\n",(s+i)->name);
   printf("%s",(s+i)->author);
   }
   free(s) ;
   free(r);
return(0);
getch();


}
x