This is first article, just for test this blog.
从下面的插入代码可以看出,这个代码插入的功能,很是不足。Tab 键被滤掉了。只能用空格进行缩进。
#include <stdio.h>
void ParseHardwareID(LPCTSTR pHardwareID, LPTSTR pVID, int cchVID, LPTSTR pPID, int cchPID);
int main(int argc, char* argv[]) {
//main 函数里是用 4 个空格进行缩进的。
VID[8], PID[8];
TCHAR
ParseHardwareID(_T("USB\VID_046D&PID_0826&REV_0010&MI_02"),
VID, _ARRAYSIZE(VID), PID, _ARRAYSIZE(PID));
%s, PID: %s;\n"), VID, PID);
_tprintf_s(_T("VID:
printf("你们觉得这里好用吗?");
return 0; } void ParseHardwareID(LPCTSTR pHardwareID, LPTSTR pVID, int cchVID, LPTSTR pPID, int cchPID)
{
bool bVIDFound = false;
bool bPIDFound = false;
const TCHAR *p1 = pHardwareID;
const TCHAR *pStopPos = NULL;
int cchCopy = 0;
while(*p1)
{
if(!bVIDFound && _tcsnicmp(p1, _T("VID_"), 4) == 0)
{
pStopPos = p1 + 4;
while(*pStopPos != 0 && *pStopPos != _T('&'))
{
++pStopPos;
}
cchCopy = min(cchVID - 1, pStopPos - p1 - 4);
_tcsncpy_s(pVID, cchVID, p1 + 4, cchCopy);
//append null-terminator;
pVID[cchCopy] = 0;
p1 = pStopPos;
bVIDFound = true;
continue;
}
if(!bPIDFound && _tcsnicmp(p1, _T("PID_"), 4) == 0)
{
pStopPos = p1 + 4;
while(*pStopPos != 0 && *pStopPos != _T('&'))
{
++pStopPos;
}
cchCopy = min(cchPID - 1, pStopPos - p1 - 4);
_tcsncpy_s(pPID, cchPID, p1 + 4, cchCopy);
//append null-terminator;
pPID[cchCopy] = 0;
p1 = pStopPos;
bPIDFound = true;
}
if(bVIDFound && bPIDFound)
break;
++p1;
}
if(!bVIDFound) pVID[0] = 0;
if(!bPIDFound) pPID[0] = 0;
}
我的博客园博客: http://www.cnblogs.com/hoodlum1980
我的知乎个人主页: hoodlum1980