本文共 2135 字,大约阅读时间需要 7 分钟。
1 第一种: 参数是入参也是出参 函数里面的*pmon 是指针指向的值;
//得到指定月份的上一个月份;
void get_prev_month(INT32 *pYear, INT32 *pMon)
{
if ( *pMon == 1 )
{
*pYear -= 1;
*pMon = 12;
}
else
{
*pMon -= 1;
}
}
2
//字符串转换成字符数组
//输入 src指针 ,输出 des指针,函数的作用是改变des指针指向的位置的值
void str2byte(CHAR *src, UINT8 *des, INT32 length) //jlb 如果输出参数是一个* ,则des[i]
{
INT32 i;
CHAR tmp[3];
memset(tmp, 0, sizeof(tmp));
for(i = 0; i < length; i++)
{
tmp[0] = src[i * 2];
tmp[1] = src[i * 2 + 1];
des[i] = strtol(tmp, NULL, 16);
}
}
3
CHAR *write_buf=malloc(16);
// 输入 t_sys_time;输出 write_buf数组
encodeFramBuf(t_sys_time,&write_buf);
VOID encodeFramBuf(RTC_TIME sys_time,CHAR **writebuf)
//jlb 如果输出参数是两个* ,则(*writebuf)[0]
{
(*writebuf)[0]=((sys_time.tm_year) / 100);
(*writebuf)[1] = ((sys_time.tm_year ) % 100);
(*writebuf)[2] = (sys_time.tm_mon );
(*writebuf)[3] = (sys_time.tm_mday);
(*writebuf)[4] = (sys_time.tm_hour);
(*writebuf)[5] = (sys_time.tm_min);
(*writebuf)[6] = (sys_time.tm_sec);
}
4
CHAR *write_buf=malloc(16);
// 输入 t_sys_time;输出 write_buf数组
encodeFramBuf(t_sys_time,write_buf);
VOID encodeFramBuf(RTC_TIME sys_time,CHAR *writebuf)
//jlb 如果输出参数是1个* ,则writebuf[0]
{
writebuf[0]=((sys_time.tm_year) / 100);
writebuf[1] = ((sys_time.tm_year ) % 100);
writebuf[2] = (sys_time.tm_mon );
writebuf[3] = (sys_time.tm_mday);
writebuf[4] = (sys_time.tm_hour);
writebuf[5] = (sys_time.tm_min);
writebuf[6] = (sys_time.tm_sec);
}
5 重重之重的
unsigned char * buff_p;
pyldLen=prime_recv(&remoteLLCAddr, &remoteSap, &srcSap,&buff_p);
//经过上面prime_recv函数之后,可以将buff_p的值打印出来,
for(i=0;i < pyldLen;i++) { printf("%02x ", buff_p [i]); }
int prime_recv(int * premoteLLCAddr, int * premoteSap, int * psrcSap, unsigned char**ppyldBuff_p)
{
int nRet = 0;
{
// get MAC Address by Serial Number
nRet = g_tVar.nRxBufLen;
*ppyldBuff_p = g_tVar.RxBuf;// g_tVar.RxBuf是ST封装的物理层读取的BUF,所以这里用指针最好。 ppyldBuff_p是二重指针,*ppyldBuff_p是减去一层指针
g_tVar.nRxBufLen = 0;
*premoteLLCAddr = g_tVar.RxSA;// premoteLLCAddr是一重指针,*premoteLLCAddr是取里面的内容 下面两个相同
*premoteSap = g_tVar.RxSSAP;
*psrcSap = g_tVar.RxDSAP;
}
return nRet;
}
6 备注:出参是一个*的
输出一个字节的话,比如例子5的:*premoteSap = g_tVar.RxSSAP;
输出多个字节的话:比如例子 4 的 writebuf[0]、writebuf[1]、。。。。。。。。
转载地址:http://rghxi.baihongyu.com/