LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   C program to see user log on in system and print user with real user name also (https://www.linuxquestions.org/questions/programming-9/c-program-to-see-user-log-on-in-system-and-print-user-with-real-user-name-also-394399/)

naveen245 12-19-2005 02:43 AM

C program to see user log on in system and print user with real user name also
 
WHAT IS WRONG WID THIS PROGRAM


#include <sys/types.h>
#include <utmp.h>
#include <pwd.h>
#include <stdio.h>

int main(int argc, char *argv[]){

struct passwd *buffer;
struct utmp *naveen;
{
while((buffer=getpwent()!=NULL))
printf("%s", buffer->pw_gecos);
printf("%s", naveen->ut_user);
}

}

jim mcnamara 12-19-2005 09:23 AM

You need to call getutid() on the utmp file to get information about that user's last login. Also your while loop "isn't" whar you think.
Code:

#include <sys/types.h>
#include <utmp.h>
#include <pwd.h>
#include <stdio.h>

int main(int argc, char *argv[]){

  struct passwd *buffer;
  struct utmp *naveen;

  while((buffer=getpwent()!=NULL)){
      printf("%s", buffer->pw_gecos);
      <--------- get a utmp record here -------->
      printf("%s", naveen->ut_user);
  }
  return 0;
}


naveen245 12-21-2005 12:53 AM

jim i didnt get you dude. Can you please show it


All times are GMT -5. The time now is 10:43 PM.