UNIX环境下C语言实现客户端查询当前用户最后登录时间并按指定格式输出
问题背景
我是编程新手,目前在Putty(UNIX)环境下使用单个.c文件进行开发,现有代码可按[YYYY:MM:DD:HR:MN:SEC]格式打印当前本地时间。
需求说明
运行客户端程序时,从服务端获取客户端当前用户的最后登录时间,且采用和当前时间打印逻辑相同的[YYYY:MM:DD:HR:MN:SEC]格式输出。
遇到的问题
原生shell的last命令输出格式为「工作日、月份、当月日期、时:分」,不符合格式要求,因此需要自行编写C/S架构的C代码实现需求。
现有参考代码片段
#include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <netdb.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <arpa/inet.h> #include <time.h> #define DAYSIZE 80 #define Month 12 #define RCVBUFSIZE 1024 #define SNDBUFSIZE 1024 fprintf(stderr, "The last time connected [%d:%s:%d:%2d:%2d:%2d] is the last time when the client program disconnected from the server using the Quit command \n",year,m,wd,hr,mn,sc);
内容的提问来源于stack exchange,提问作者NewGuy
相关产品推荐
相关产品推荐

