linux下c语言关机程序
/* Offtimer.c.For auto halt. */
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#define DELAY 60/* Time of sleeping */
int main()
{
time_t now;
struct tm *p;
while(1)
{
now = time(NULL);
sleep(DELAY);/* To reduce cpu occupation */
p = localtime(&now);
if ((p->tm_hour = 14) && (p->tm_min >= 30))/ *This means the system will halt after 14:30 or 14:31 */
system("poweroff"); / *'poweroff' is the command in Red Flag Linux
Desktop 5.0 to turn off the computer.To do this you should be root. */
}
return 0;
}
引用gcc编译,另外需要有root用户的权利才能行。
相关文档:
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define err(msg) perror(msg)
static void mkdirs(const char *dir)
{
char tmp[1024];
char *p;
&nbs ......
C,C++网络编程学习简明指南
1. 扎实的C,C++基础知识
参考资料《C程序设计》,《C++ primer》。
2. TCP/IP协议
经典书是:W.Richard Stevens 著《TCP/IP详解》三卷书,卷1是协议,卷2是实现,卷3是TCP事务协议等。还有官方的协议文档:RFC
当然也可以在网上下载电子书。
经典的开源协议分析工具:Wireshark.
......
#include <Windows.h>
#include <math.h>
#include "resource.h"
#define PI 3.1415976/180
int dwCenterX,dwCenterY,dwRadius;
const TCHAR *szAppName=TEXT("Clock");
LRESULT CALLBACK ProcWinMain(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
void ShowTime(HWND hwnd,HDC hdc);
void ......
编译,编译程序读取源程序(字符流),对之进行词法和语法的分析,将高级语言指令转换为功能等效的汇编代码,再由汇编程序转换为机器语言,并且按照操作系统对可执行文件格式的要求链接生成可执行程序。
C源程序头文件-->预编译处理(cpp)-->编译程序本身-->优化程序-->汇编程序-->链接程序--> ......