LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-19-2005, 03:43 AM   #1
naveen245
LQ Newbie
 
Registered: Dec 2005
Posts: 4
Blog Entries: 1

Rep: Reputation: 0
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);
}

}
 
Old 12-19-2005, 10:23 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 34
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;
}
 
Old 12-21-2005, 01:53 AM   #3
naveen245
LQ Newbie
 
Registered: Dec 2005
Posts: 4
Blog Entries: 1

Original Poster
Rep: Reputation: 0
jim i didnt get you dude. Can you please show it
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Load kde profile from /mnt/removable/user instead of /home/user preacher.ca Linux - General 3 12-02-2005 04:00 PM
Samba -- XP user can log in to shares but smbclient user always gets password errors ejoe Linux - Software 3 04-18-2005 11:55 AM
regular user program causing system freeze win32sux Slackware 2 02-07-2005 08:32 PM
grant user access to /fat-c & copying users' preferences to another user n0x Linux - Newbie 1 07-04-2004 01:04 AM
Games runs slow as normal user, but fast as root user mcore Linux - Software 2 06-08-2004 12:11 AM


All times are GMT -5. The time now is 02:21 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration