
编程技巧及算法
智能高科
这个作者很懒,什么都没留下…
展开
-
在定时器中查看刷帧数率fps的方法(c语言实现)
在定时器中刷帧数的方法将帧数打印在屏幕上 static char* My_IntToWideChar1(int i, char* buf){ return (char*)_itow(i, (LPWSTR)buf, 10);}void My_DrawFPS(HDC hdc){ static uint t = 0; uint fps = 0原创 2013-07-12 17:31:16 · 2064 阅读 · 0 评论 -
函数指针数组
//计算器程序中使用函数指针数组v1.0///////作者:郝效禹#include "stdio.h"double add(double a,double b){return a + b;}double sub(double a,double b){return a - b;}double mul(double a,double b){retur原创 2013-07-14 11:30:54 · 652 阅读 · 0 评论 -
回调函数(c语言)
/////////////////////////////////////#include "stdio.h"//***********************用户可编辑使用的函数void callback_good(){printf("so good!\n");}void callback_bad(){printf("so bad!\n");}void原创 2013-07-14 11:31:52 · 563 阅读 · 0 评论 -
lua输出arg参数的函数(lua语言)
function unpack(t, i) i = i or 1 if t[i] then return t[i], unpack(t, i + 1) endendfunction fwrite(fmt, ...) return io.write(string.format(fmt, unpack(原创 2013-07-14 01:55:17 · 3197 阅读 · 0 评论 -
lua求表中最大值序号及最大值的的函数(lua实现)
function maximum (a) local mi = 1 -- maximum index local m = a[mi] -- maximum value for i,val in ipairs(a) do if val > m then mi = i原创 2013-07-14 02:06:48 · 4666 阅读 · 0 评论 -
程序的内存分配
程序的内存分配(堆和栈区别)一、预备知识 程序的内存分配一个由c/C++编译的程序占用的内存分为以下几个部分1、栈区(stack) 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。2、堆区(heap) 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 。注意它与数据结构中的堆是两回事,分配方式倒是类原创 2013-07-14 11:05:55 · 516 阅读 · 0 评论 -
is it right?(c语言)
#include "stdafx.h"#include #include void getptr(char * p){p = (char*)malloc(100);}int main(int argc, char* argv[]){char * pp = NULL;getptr(pp);strcpy(pp,"Hello World!");pr原创 2013-07-14 00:47:33 · 812 阅读 · 0 评论 -
strange c define for macro and array(c语言)
const char * mychar[] = {#define str1 "hello""sssss"};原创 2013-07-14 00:58:06 · 967 阅读 · 0 评论 -
a good example my call back(c语言实现)
#include "stdafx.h"#include "stdio.h"int m = 1;void fcall(int state){switch(state){case 1: printf("state one!\n"); break;case 2: printf("state two!\n"); break;def原创 2013-07-14 01:35:21 · 771 阅读 · 0 评论 -
字符串逆序(lus实现)
function reverse(s) local r = "" for i = #s, 1, -1 do r = r .. string.sub(s, i, i) end return rendio.write("Input a string: ")s = io.read()io.write("The reverse原创 2013-07-14 01:46:20 · 672 阅读 · 0 评论 -
lua调用外部lua方法 (lua语言)
“foo.lua”文件:function foo (x) print(x)endfunction honghong()print("honghong")end--主lua文件function dofile (filename) local f = assert(loadfile(filename))原创 2013-07-14 01:49:29 · 4006 阅读 · 1 评论 -
lua 用闭包写的按钮程序(lua)
function func (sel) --按钮虚拟响应效果函数if(sel == 1) thenprint("key1")else if(sel == 2) thenprint("key2")else if(sel == 3) thenprint("key3")elseprint("null")endende原创 2013-07-14 01:50:52 · 961 阅读 · 0 评论 -
lua运算符优先级表(lua语言)
^not - (unary)* /+ -.. = ~= ==andor除了^和..外所有的二元运算符都是左连接的原创 2013-07-14 02:03:50 · 3599 阅读 · 0 评论 -
c语言多参数函数写法
#include"stdio.h"////多参数////////////////long sum(int i,...){int *p,j;long s = 0;p = &i+1;for (j=0;j s += p[j]; return s;}void main(){long Sum = sum(3,1,2,3);printf("原创 2013-07-14 11:17:59 · 2755 阅读 · 0 评论 -
数组名与地址以及二维数组下标用法(c语言)
一、数组名与地址int a[3],大多数早期版本的c语言实现中,并没有所谓“数组的地址”这一概念,因此&a或者被视为非法,或者就等于a。二、二维数组下标用法int calendar[12][31];int *p;int i;calendar[4]当做数组calendar[4]下标为0的数组元素的地址处理,除了sizeof,&i原创 2013-07-14 11:10:16 · 2121 阅读 · 0 评论 -
skill c for macro (c语言)
#include "stdafx.h"#include "stdio.h"#define myprint(x) printf(x);printf("\n\n")int main(int argc, char* argv[]){myprint("hello World!");return 0;}原创 2013-07-14 01:45:18 · 982 阅读 · 0 评论 -
c语言动态创建二维数组的方法
#include"stdio.h"#include"string.h"#include"stdlib.h"#include"malloc.h"//动态创建二维数组方法一:typedef enum{ style_char, style_short, style_int}Array2Style;typedef struct{ int line;原创 2013-07-13 22:50:06 · 1791 阅读 · 0 评论 -
绘制多行文字代码(c语言实现)
1、头文件#ifndef _MULTITEXT_H_#define _MULTITEXT_H_#include "vrecommon.h"#define MULTITEXT_LINE_NUMBER (100)#define MULTITEXT_ALIGN_LEFT (1#define MULTITEXT_ALIGN_HCENTER (1#define MULTITEXT原创 2013-07-12 17:38:27 · 1128 阅读 · 0 评论 -
封装一个函数可以在屏幕上打印信息信息(c)语言例子
void printf_on_screen(uint value,int x,int y){ char str[50] = {0}; My_DrawText1(GameSys.hdc,My_IntToWideChar1(value, str), x, y, 50, 50, 255, 0, 0);}//如果是刷屏操作,在定时器回调结束时调用原创 2013-07-12 17:25:59 · 947 阅读 · 0 评论 -
清空数据的方法(c语言实现)
自己总结的几条数据清空的方法:1、在代码设计的时候变量的默认初始值最好为0或者NULL。2、如果是整型或者是字符型的清零就设置为0和0;3、数组char array[ARRAY_LEN];的清空最好用memset(array,0,sizeof(array));4、结构体的清空最好也用memset(structdata,0,sizeof(structdata));原创 2013-07-12 17:37:05 · 4278 阅读 · 0 评论 -
给结构整体赋值(c语言实现)
#include"stdio.h"#include"string.h"#include"stdlib.h"#include"malloc.h"struct s_tag { int b; int a[100];};struct s_tag orange,lime,lemon;struct s_tag twofold(struct s_tag s原创 2013-07-13 22:48:28 · 1205 阅读 · 0 评论 -
C语言运算符及优先级
附录:C语言运算符及优先级优先级 运算符 含义 运算符类型 结合方向15 () 圆括号 单目 自左向右 [] 下标运算符原创 2013-07-14 00:42:48 · 578 阅读 · 0 评论 -
vc++实现多线程程序
#include #include DWORD WINAPI Fun1Proc(LPVOID lpParameter // thread data);DWORD WINAPI Fun2Proc(LPVOID lpParameter // thread data);int index=0;int tickets=100;HANDLE hMute原创 2013-07-14 00:49:39 · 601 阅读 · 0 评论 -
how to use typedef enum(c语言)
#include "stdafx.h"typedef enum{one = 5,two,three,} MMI_3D_GAME_LIST_ENUM;MMI_3D_GAME_LIST_ENUM a = three;int main(int argc, char* argv[]){printf("%d\n",a);return 0;}原创 2013-07-14 00:55:21 · 645 阅读 · 0 评论 -
strange c use for macro very good(c语言)
#include "stdafx.h"#include "myhead.h"#define MMI_3D_GAME_SWITCH(_index) \{ \ case _index:原创 2013-07-14 00:56:30 · 818 阅读 · 0 评论 -
loadstring表达式求值(lua语言)
print "enter your expression:"a = 2b = 3local l = io.read()local func = assert(loadstring("return " .. l))print("the value of your expression is " .. func())enter your expressi原创 2013-07-14 01:48:19 · 1053 阅读 · 0 评论 -
用lua写一个闭包的例子(lua语言)
function func (sel)if(sel == 1) thenprint("hello 1")else if(sel == 2) thenprint("hello 2")else if(sel == 3) thenprint("hello 3")elseprint("nobody")endendend原创 2013-07-14 01:53:52 · 726 阅读 · 0 评论 -
lua 中调用函数特殊的写法(lua语言)
上述规则有一个例外,当函数只有一个参数并且这个参数是字符串或者表构造的时候,()可有可无:print "Hello World" print("Hello World")dofile 'a.lua' dofile ('a.lua')print [[a multi-line print([[a m原创 2013-07-14 02:11:15 · 1943 阅读 · 0 评论 -
C语言警报声程序
#include "stdio.h"int main(void){ int i,j; for(j = 0;j { sound(1000); for(i = 0;i delay(10000); sound(700); for(i = 0; i delay(10000);} nosound(); r原创 2013-07-14 11:30:16 · 10603 阅读 · 0 评论