void StrSplit(int n, char *buf, char *buf2) { int i = 0; static int count = 0; /*使用静态局部变量count计数*/ if (count == strlen(buf)) count = 0; for (i = 0; i < n; i++) { buf2[i] = buf[count]; count++; } buf2[i] = ' '; return ; } /*十六进制地址转换*/ void StrChange(char *address, char *src,int num) { int i; int n = num; char buf[3] = {0}; for(i = 0; i < n; i++) { sprintf(buf, "%02x",src[i]); printf("%s ",buf); strncat(address, buf,2); memset(buf, 0, sizeof(buf)); } return; } void SubString(char *dest, char *src, int start, int end) { int i = start; if (start > strlen(src)) return; if (end > strlen(src)) end = strlen(src); while (i < end) { dest[i-start] = src[i]; i++; } dest[i-start] = ' '; return; }
最近一直搞得比较简单的小程序··也就是串口接收数据的接收和解析,老感觉没什么干劲··记录下常用的两个分解字符串的函数吧,新手简单小程序···