#include #include #include using namespace std; #include void show_info(struct utmp * current_record) { if (current_record->ut_type==USER_PROCESS) { char * s=ctime(¤t_record->ut_time)+4; /*start at month*/ s[12]='\0'; /*end at minutes*/ cout<ut_name<<"\t"<ut_line<<"\t"<ut_host)!=0) cout<ut_host; cout<<"\n"; } } void show_info(struct utmp * records, int n) { for (int i=0; iut_time; int j=record2->ut_time; if (ij) return 1; } int main() { struct utmp * records; ifstream utmpfile(UTMP_FILE, ios::in | ios::binary); //determine num of records utmpfile.seekg(0, ios_base::end); int n=utmpfile.tellg()/sizeof(utmp); utmpfile.seekg(0, ios_base::beg); records=new utmp[n]; int i=0; while(true) { utmpfile.read((char *)(records+i++), sizeof(utmp)); if (utmpfile.eof()) { break; } } qsort(records, n, sizeof(utmp), &compare); show_info(records, n); utmpfile.close(); delete[] records; cout<