Shutdown程序源码学习笔记

本文提到的shutdown程序是cygwin下的开源程序shutdown(源码)

C语言字符串操作

  1. strrchr(str, ch):该函数返回ch字符在str(C语言字符串)中最后出现的位置(即一个指针),如果不存在,则返回NULL指针。头文件:string.h
  2. strcasecmp(str1, str2):该函数忽略大小写来比较str1和str2两个字符串的内容,如果相等则返回0,如果str1大于str2则返回大于0的值,str1小于str2则返回小于0的值。头文件:string.h
  3. isdigit(ch):检查ch字符是否为数字0-9。如果ch是数字,则返回TRUE,否则返回0头文件:ctype.h
  4. strtol(nptr, endptr, base): 根据base把nptr字符串转换成十进制整数。base的范围为2-36,或者0(表示十进制)。endptr为非NULL时,strtol会将把在遍历nptr时遇到不合条件而终止的字符指针由endptr返回。

C语言返回本地时间

在C语言中关于时间操作相关的函数:localtime(time_t&)asctime()等,具体用法如下:

#include <stdio.h>
#include <time.h>
int main()
{
    time_t rawtime;
    struct tm* timeinfo;

    rawtime = time(NULL); // 获取当前系统时间与1970-1-1零点零分偏移的秒数
    timeinfo = localtime(&rawtime); // 把秒数转换成本地时间

    // 以"hh:mm:ss"格式输出
    printf("Current local time:%d:%d:%d", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);

    //"Www Mmm dd hh:mm:ss yyyy"格式输出
    printf("Current local date/time is: %s", asctime(timeinfo));

    // 把本地时间转换为距1970-1-1零点零分的总秒数
    printf("Current time %ld seconds:", mktime(timeinfo));

    return 0;
}

Windows关机函数

  1. ExitWindowsEx(),该函数可以注销当前用户会话,或关闭系统,或重启系统。
  2. InitiateSystemShutdownEx(),该函数以可选的方式来关闭系统,且可以选择记录关闭系统的原因。
  3. AbortSystemShutdownW(),该函数用来终止一个关机操作。当用InitiateSystemShutdownEx等相似函数来关闭系统时,在timeout时间范围内,可以调用AbortSystemShutdownW来阻止系统关闭。

猜你喜欢

转载自blog.csdn.net/LYH66/article/details/50075877