#include<stdio.h>
#include<utmp.h>
#include<fcntl.h>
main()
{
int fd;
fd=open("/var/run/utmp",O_RDONLY);
perror("open");
struct utmp array;
read(fd,&array,sizeof(struct utmp));
perror("read");
printf("%s\n",array.ut_user);
}
为什么read有问题???应该怎么改?
已改.
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <utmp.h>
#include <fcntl.h>
main()
{
int fd;
fd=open("/var/run/utmp",O_RDONLY);
perror("open");
struct utmp array;
while(read(fd,&array,sizeof(struct utmp)) > 0){
printf("%s\n",array.ut_user);
}
return(0);
}