c program by using
structure to pointers
#include<stdio.h>
#include<string.h>
struct student
{
int id;
char name[30];
float percentage;
};
void main()
{
int I;
clrscr();
struct student
record1={1,’xxxx”,36.5}
struct student record2,
*record3, *ptr1, record4;
printf(“Records of
STUDENT1-record structure \n);
printf(“Id:%d\n Name:%s\n
Percentage:%f\n”, record1.id, record1.name, record1.percentage);
record2=record1;
printf(“Records of
STUDENT1-Direct copy from record1 \n);
printf(“Id:%d\n Name:%s\n Percentage:%f\n”,
record2.id, record2.name, record2.percentage);
ptr1=&record1;
memcpy(record3, ptr1,
sizeof(record1));
printf(“Records of STUDENT1-
copied from record1 using memcpy \n);
printf(“Id:%d\n Name:%s\n
Percentage:%f\n”, record3.id, record3.name, record3.percentage);
ptr1=&record1;
memcpy(record3, ptr1,
sizeof(record1));
printf(“Records of STUDENT1-
copied individual members from
record1 \n);
printf(“Id:%d\n Name:%s\n
Percentage:%f\n”, record4.id, record4.name, record4.percentage);
strcpy(record4.name,record1.name);
record4.percentage = record1.percentage;
printf(" Id : %d \n
Name : %s\n Percentage :
%f\n", record4.id, record4.name, record4.percentage);
getch();
}
No comments:
Post a Comment