MarkSheet Preparation Using SharedMemory –I | URDINESH

Software Programming, Tutorials, Interview Preparations,Stock Market,BSE/NSE, General informations

Saturday, August 1, 2015

MarkSheet Preparation Using SharedMemory –I

PROGRAM:

#include<sys/types.h>
#include<sys/ipc.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,0600|IPC_CREAT);
if(shmid==-1)
{printf("shmget failed");
return;
}
p=(struct stud *)shmat(shmid,0,0);
if(p==(void *)-1)
{
printf("shmat failed");
return;
}
printf("Enter the name:\n");
scanf("%s",p->name);
printf("Enter the Roll.No:\n");
scanf("%d",&p->roll);
printf("Enter the marks  got in 3 subject: \n");
scanf("%d%d%d",&p->m1,&p->m2,&p->m3);
printf("\nThe given information is placed in shared memory\n");
}


OUTPUT:

[user @localhost ~]$ cc marsh.c
[user @localhost ~]$ ./a.out
Enter the name:
Kannan
Enter the Roll.No:
987
Enter the marks  got in 3 subject:
89 98 78

The given information is placed in shared memory
[user @localhost ~]$


No comments:

Post a Comment

Thanks for your valuable comments

Followers