G
grocery_stocker
#include <stdio.h>
#include <utmp.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
static int user_info(struct utmp *user){
setutent();
printf("%12s %8s %22s %14s",
user->ut_user,
user->ut_line,
user->ut_host,
ctime(&user->ut_time)
);
endutent();
return 0;
}
int main(void) {
struct utmp log_file;
FILE *fp;
print_banner();
for((fp =
fopen("/var/log/wtmp","r"))!=0;fread(&log_file,sizeof(struct
utmp),1,fp) !=0
{
user_info(&log_file);
/*if(!feof(fp)){
perror( "End of File \n" );
exit(EXIT_SUCCESS);
}
if(fp == NULL) {
fprintf(stderr,"Can't open file\n");
exit(EXIT_SUCCESS);
}*/
fclose(fp);
}
}
Why does this only output one line from the following:
$./emulate
Name Terminal Hostname Time
reboot ~ 2.6.4-52-default Tue Jun 21 07:38:30 2005
End of File
: Permission denied
Why doesn't the loop go through the entire file?
#include <utmp.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
static int user_info(struct utmp *user){
setutent();
printf("%12s %8s %22s %14s",
user->ut_user,
user->ut_line,
user->ut_host,
ctime(&user->ut_time)
);
endutent();
return 0;
}
int main(void) {
struct utmp log_file;
FILE *fp;
print_banner();
for((fp =
fopen("/var/log/wtmp","r"))!=0;fread(&log_file,sizeof(struct
utmp),1,fp) !=0
user_info(&log_file);
/*if(!feof(fp)){
perror( "End of File \n" );
exit(EXIT_SUCCESS);
}
if(fp == NULL) {
fprintf(stderr,"Can't open file\n");
exit(EXIT_SUCCESS);
}*/
fclose(fp);
}
}
Why does this only output one line from the following:
$./emulate
Name Terminal Hostname Time
reboot ~ 2.6.4-52-default Tue Jun 21 07:38:30 2005
End of File
: Permission denied
Why doesn't the loop go through the entire file?