主要是为了代码重用。
#include <stdio.h> #include <stdlib.h> #include <Windows.h> void OpenBaidu() { ShellExecuteA(0, "open", "http://www.baidu.com", 0, 0, 3); } void CloseBaidu() { system("taskkill /f /im 360se.exe"); } void Input()//模拟键盘输入xianhua { keybd_event('X', 0, 0, 0);//按下 keybd_event('X', 0, 2, 0);//抬起 Sleep(300); keybd_event('I', 0, 0, 0); keybd_event('I', 0, 2, 0); Sleep(300); keybd_event('A', 0, 0, 0);//按下 keybd_event('A', 0, 2, 0);//抬起 Sleep(300); keybd_event('N', 0, 0, 0);//按下 keybd_event('N', 0, 2, 0);//抬起 Sleep(300); keybd_event('H', 0, 0, 0);//按下 keybd_event('H', 0, 2, 0);//抬起 Sleep(300); keybd_event('U', 0, 0, 0);//按下 keybd_event('U', 0, 2, 0);//抬起 Sleep(300); keybd_event('A', 0, 0, 0);//按下 keybd_event('A', 0, 2, 0);//抬起 Sleep(300); keybd_event(0x0D, 0, 0, 0);//按下回车 keybd_event(0x0D, 0, 2, 0);//抬起 } void Click()//鼠标单击 { //移动到屏幕位置 //mouse_event(MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE, 200 * 65535 / 1440, 400 * 65535 / 900, 0, 0); SetCursorPos(200, 400); Sleep(2000); mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); } void main() { for (;;) { OpenBaidu(); Sleep(5000); Input(); Sleep(3000); Click(); Sleep(5000); CloseBaidu(); } }
#include <stdio.h> #include <stdlib.h> void main() { int a[10] = { 0 }; time_t ts; srand((unsigned int )time(&ts)); for (int i = 0; i < 10; i++) { a[i] = rand()%100; printf("%d, ", a[i]); } printf("\n"); for (int i = 0; i < 10; i++) { printf("%d, %d ,%x, %x\n",a[i],*(a+i), &a[i], (a+i)); } system("pause"); }
#include <stdio.h> #include <stdlib.h> void SelectSort(int a[], int n) { int i, j, min, temp; for (i = 0; i < n; i++) { min = i;//min为最小值的数组下标 for (j = i + 1; j < n; j++) { if (a[j] < a[min]) { min = j; } } if (min != i) { temp = a[min]; a[min] = a[i]; a[i] = temp; } } } void main() { int a[10] = { 0 }; time_t ts; srand((unsigned int )time(&ts)); for (int i = 0; i < 10; i++) { a[i] = rand()%100; printf("%d, ", a[i]); } printf("\n"); SelectSort(a, 10); for (int i = 0; i < 10; i++) { printf("%d, ", a[i]); } system("pause"); }
#include <stdio.h> #include <stdlib.h> void BubbleSort(int a[], int n) { int i, j, temp; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - 1 - i; j++) { if (a[j]>a[j + 1]) { temp = a[j]; a[j] = a[j + 1]; a[j + 1] = temp; } } } } void main() { int a[10] = { 0 }; time_t ts; srand((unsigned int )time(&ts)); for (int i = 0; i < 10; i++) { a[i] = rand()%100; printf("%d, ", a[i]); } printf("\n"); BubbleSort(a, 10); for (int i = 0; i < 10; i++) { printf("%d, ", a[i]); } system("pause"); }
#include <Windows.h> void main() { char buf[100] = { 0 }; int i = 3; sprintf(buf, "E:\\bj\\%d.jpg", i); SystemParametersInfoA(20, 0, buf, 3);//20--桌面背景, 3--立即执行 //SystemParametersInfoA(20, 0, "E:\\bj\\0.jpg", 3);//20--桌面背景, 3--立即执行 ShellExecuteA(0, "open", "E:\\bj\\0.mp3", 0, 0, SW_NORMAL);//播放音乐 }