write a program by giving the name of the user and program will report you as soon as he login.

6:48 PM

write a program by giving the name of the user and program will report  you as soon as he login.

#include<sys/types.h>
#include<stdio.h>
#include<utmp.h>
#define UTMP “/etc/utmp”

main(argc,argv)
int argc;
char * argv[];
{
  FILE *fp;
struct utmp u;
for(;;)
{
  fp=fopen(utmp,”r”);
while(!feof(fp))
{
   fread(&u,sizeof(u),1,fp);
if (u.ut_name==NULL)
 continue;
   if(strcmp(argv[1],u.ut_name)==0)
{

  printf(“\n\7\7\7 %s has login \n”,argv[1]);
  exit(0);
}
}

fclose(fp);
sleep(5);
}
}

0 Comments