Documente Academic
Documente Profesional
Documente Cultură
PART A
Answer:1:
Break;
Case 3: //display info of all user
Printf(“user is: %s \n”,getlogin());
Printf(“user ids: uid=%d, gid=%d \n’,uid,gid);
Pw=getpwuid(uid);
Printf(“UID passwd:\n name=%s,uid=%d,gid=%d,home=%s,shell=
%s\n”,pw->pw_name, pw->pw_uid, pw->pw_gid, pw->pw_dir, pw-
>pw_shell);
Pw=getpwname(“root”);
Printf(“root password entry:”);
Printf(“name: %s, uid:%d, gid:%d,home=%s,shell=%s”, pw->pw_name,
pw->pw_uid, pw->pw_gid, pw->pw_dir, pw->pw_shell);
Exit(0);
Break;
Case 4:// case for quite
Return (0);
Break;
Defsult:
Printff(“wrong choice”);
} //closing of switch case portion
getch();
return (0);
}
===========================================================
Ans: 2
#inlcude<stdlib.h>
#include<unistd.h>
#inlcude<stdio.h>
#inlcude<time.h>
int main()
{
int i,choice;
time_t the_time,timeval;
struct tm *tm_ptr;
printf(“1. Display system time \n 2. Display date in year-month-day format”);
printf(“3. Add current user & time in log file \n 4. Display date & time without
gmtime”);
printf(“make your choice:”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:
for(i=1;i<5;i++)
{
the_time=time((time_t *)0);
printf(“the system time is %ld”, the_time);
sleep(1);
}
break;
case 2:
(void)time(&the_time);
tm_ptr=gmtime(&the_time);
printf(“date is: %02d:%02d:%02d”,tm_ptr->tm_year,tm_ptr->tm_mon+1, tm_ptr-
>tm_mday);
break;
case 3:
FILE *f;
F=open(“not_here”,”r”);
If(!f)
Syslog(LOG_ERR|LOG_USER,”oops - %m \n”);
exit(o);
break;
case 4:
(void)time(&timeval);
printf(“the date and time is: %s”,ctime(&timeval));
exit(0);
break;
default:
printf(“wrong choice”);
}
return (0);
}
===========================================================
Ans:3
#include<stdio.h>
#include<stdlib.h>
Int main()
{
char tmpname[L_tmpname];
char *filename;
FILE *tmpfp;
filename = tmpname(tmpname);
printf(“temporary file name is : %s”, filename);
tmpfp=tmpfile();
if(tmpfp)
{
printf(“opened a temporary file ok \n”);
}
else
{
perror(“tmpfile”);
}
exit(0);
}
========================================================
PART B
Ans: 4
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
main()
{
int fd,c, res;
struct termios oldtio,newtio;
char buf[255];
tcgetattr(fd,&oldtio);
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0;
newtio.c_cc[VMIN] = 5;
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
while (STOP==FALSE)
{
res = read(fd,buf,255);
buf[res]=0;
printf(":%s:%d\n", buf, res);
if (buf[0]=='z') STOP=TRUE;
}
tcsetattr(fd,TCSANOW,&oldtio);
}
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ans 5:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include<string.h>
struct student
{
Char name[20];
Int rollno;
Float marks;
}
int main()
{
Struct student arr[100];
int i,choice,no;
printf("\t 1.ADD NEW RECORD \n 2.DELETION”);
printf("3.DISPLAY RECORDS \n 4.QUIT);
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ans: 6
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<fcntl.h>
#include<errno.h>
int main()
{
int file_desc;
int save_errno;
file_desc = open(“Yogendra.txt”,O_RDWR|O_CREAT|O_EXCL,0444);
If (file_desc == -1)
{
save_errno = errno;
printf(“open failed with error %d \n”, save_errno);
}
else
{
printf(“file successes open \n”);
}
exit(EXIT_SUCCESS);
}
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||