PROGRAM:
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/msg.h>
#include<sys/shm.h>
#include<unistd.h>
#include<stdio.h>
#include<sys/stat.h>
#include<string.h>
struct stud
{char name[25];
int
roll,m1,m2,m3,tot;
float avg;
};
main()
{struct stud m,*p;
p=&m;
int shmid;
shmid=shmget((key_t)1300,1024,0660|IPC_CREAT);
if(shmid==-1)
{printf("shmget
failed");
return;
}
p=(struct stud
*)shmat(shmid,0,0);
if(p==(void *)-1)
{printf("shmat
failed");
return;
}
p->tot=p->m1+p->m2+p->m3;
p->avg=(float)p->tot/3.0;
printf("\nNAME:
%s",p->name);
printf("\nROLLNO:%d",p->roll);
printf("\nMARK1:%d",p->m1);
printf("\nMARK@:%d",p->m2);
printf("\nMARK#:%d",p->m3);
printf("\nTOTAL:%d",p->tot);
printf("\nAVERAGE:%f",p->avg);
}
OUTPUT:
[user @localhost
~]$ cc cmarsh.c
[user @localhost
~]$ ./a.out
NAME: Kannan
ROLLNO:987
MARK1:89
MARK@:98
MARK#:78
TOTAL:265
AVERAGE:88.333336[user
@localhost ~]$
No comments:
Post a Comment
Thanks for your valuable comments