if(3 != argc)
{
printf("the paras number is wrong\n");
return TCL_OK;
}
if(TCL_OK != Tcl_GetInt(interp, argv[2], &iPos))
{
printf("the para 2 is wrong\n");
return TCL_OK;
}
rCode = GetWordFromStr(argv[1], pDestStr, iPos);
if(rCode == RET_OK)
{
printf("The Destine string is %s\n", pDestStr);
}
else
{
printf("It's fail to get the string!\n");
}
return TCL_OK;
}
int Tcl_AppInit(Tcl_Interp *interp)
{
Tcl_CreateCommand(interp, "GetWord", (Tcl_CmdProc *)Tcl_EXGetWord,
(ClientData)NULL, (Tcl_CmdDeleteProc *)NULL);
return TCL_OK;
}
int GetWordFromStr(char *pstrSource, char *pstrDest, int iPos){
if(pstrSource == NULL || pstrDest == NULL || iPos<0)
return false;
//strncpy(pstrDest, pstrSource, iPos);
return true;
}
添加tcl头文件和库文件,并设置相应的头文件和库文件路径
头文件路径:ActiveTcl 8.4安装目录/lib/ tcl8.4
库文件路径:ActiveTcl 8.4安装目录/bin
编译通过后,运行,出现控制台程序,输入GetWord “wo ai zhong guo” 3,则出现如下的结果界面。
文章来源于领测软件测试网 https://www.ltesting.net/