_stricmp在string匹配时返回错误的值。该怎么办?

_stricmp在string匹配时返回错误的值。该怎么办?,第1张

概述_stricmp在string匹配返回错误的值。 该怎么办?

我有这样的代码:

second = strtok (NulL,"n"); logprintf(second); if(_stricmp(second,"windows") == 0)

logprintf将数据打印到日志文件中,并打印“windows”(不含引号)。

但_stricmp以某种方式返回13。所以if检查永远不会被传递。 我试过做sscanf / sprintf /其他string的方式,但没有工作。 我没有想法。

完整的代码:

如何使用BASH比较两个文本文件的相同的确切文字?

在另一个内部find一个声音文件

我需要一个Win / linux二进制比较工具

windows服务和常规应用程序有什么区别?

cmp命令返回EOF在我的输出尽pipe完全匹配,据我所知

#ifdef WIN32 char buf[65535]; bool found = false; bool install = false; bool installing = false; unsigned int installed = 0; WIN32_FIND_DATA fd; HANDLE h = FindFirstfile(L"./*.aifPAK",&fd); char * name = NulL; char * ID = NulL; char * AUTHOR = NulL; int VERSION; HZIP hz = OpenZip(fd.cfilename,0); ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index; for (int i=0; i<numitems; ++i) { GetZipItem(hz,i,&ze); if(found == false) { if(_wcsicmp(ze.name,L"INSTALL.aifList") == 0) { found = true; UnzipItem(hz,buf,65535); i = 0; stringstream strx; strx << buf; string line; while (getline(strx,line)) { char * first = NulL; char * second = NulL; char * third = NulL; first = strtok ((char *)line.c_str()," "); if(install == false) { if(_stricmp(first,"name") == 0) { name = strtok (NulL,"n"); } if(_stricmp(first,"ID") == 0) { ID = strtok (NulL,"AUTHOR") == 0) { AUTHOR = strtok (NulL,"VERSION") == 0) { VERSION = atoi(strtok (NulL,"n")); } if(_stricmp(first,"START_INSTALL") == 0) { second = strtok (NulL,"windows") == 0) { cout << "INSTALLAHn"; install = true; cout << name << "|" << ID << "|" << AUTHOR << "|" << VERSION << "|n"; } } } else { cout << "ELSE FirsT: " << first << "n"; if(_stricmp(first,"UNPACK") == 0) { second = strtok (NulL,">"); third = strtok (NulL,"n"); cout << first << "|" << second << "|" << third << "|n"; TodoVec.push_back(TodoInfo(0,second,third)); } if(_stricmp(first,"PRINT") == 0) { second = strtok (NulL,"n"); cout << first << "|" << second << "|" << third << "|n"; TodoVec.push_back(TodoInfo(3,"")); } if(_stricmp(first,"ADD_PLUGIN") == 0) { second = strtok (NulL,"n"); cout << first << "|" << second << "|" << third << "|n"; TodoVec.push_back(TodoInfo(1,"ADD_FILTERSCRIPT") == 0) { second = strtok (NulL,"n"); cout << first << "|" << second << "|" << third << "|n"; TodoVec.push_back(TodoInfo(2,"END_INSTALL") == 0) { break; } } } } } else { if(installing == false) { i = 0; installing = true; for(unsigned int ix = 0; ix < TodoVec.size(); ++ix) { cout << "|" << TodoVec.at(ix).action << "|" << TodoVec.at(ix).string1 << "|" << TodoVec.at(ix).string2 << "|n"; } } else { } } } found = false; install = false; installing = false CloseZip(hz); while (FindNextfile(h,&fd)) { //fnVec.push_back(fd.cfilename); } #else//assuming linux #endif

“INSTALL.aifList”文件如下所示:

name Route Connector Plugin ID GAMER_GPS VERSION 1733 AUTHOR Gamer_Z START_INSTALL windows UNPACK RouteConnector/plugins/RouteConnectorPlugin.dll>./plugins/RouteConnectorPlugin.dll UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.amx>./filterscripts/Node_GPS.amx UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.pwn>./filterscripts/Node_GPS.pwn UNPACK RouteConnector/scriptfiles/GPS.dat>./scriptfiles/GPS.dat UNPACK RouteConnector/sampGDK/EXTRACTED/libsampgdk-2.2.1-win32/bin/sampgdk2.dll>./sampgdk2.dll ADD_PLUGIN RouteConnectorPlugin ADD_FILTERSCRIPT Node_GPS END_INSTALL START_INSTALL liNUX UNPACK RouteConnector/plugins/RouteConnectorPlugin.so>./plugins/RouteConnectorPlugin.so UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.amx>./filterscripts/Node_GPS.amx UNPACK RouteConnector/examples/other/filterscripts/Node_GPS.pwn>./filterscripts/Node_GPS.pwn UNPACK RouteConnector/scriptfiles/GPS.dat>./scriptfiles/GPS.dat PRINT To make this plugin work you must install the sampgdk library from www.github.com/Zeex/ (if you don't have it installed) ADD_PLUGIN RouteConnectorPlugin.so ADD_FILTERSCRIPT Node_GPS END_INSTALL

所有的数据被正确读入'buf'。

有人可以build议如何解决这个问题?

用CMD比较文件

有一个程序可以sorting一个Lua程序输出的值吗?

如何比较linux中第一个N字节的二进制文件

windows批处理脚本:如果两个文件相同,则执行一个命令!

我怎样才能比较一个文件列表的大小,并采取最大的?

看起来好像你没有考虑CRLF行结尾。 在文本模式下打开文件会将“ r n”翻译成“ n”,但代码中没有这样做。 如果“windows”后面跟着“ r n”,那么你就把它当作“windows r”后跟一个“ n”,因为“ n”是你传递给strtok所有东西。 有几种可能的解决方案,但是一个是将“ r n”传递给strtok 。

13是回车符'r' ,所以你的输入有一个尾部的' r',打印时不显示。 要删除它,请将"rn"作为分隔符传递给strtok 。

13表示你的second字符串包含"windowsr" 。 r是一个回车符 – 在windows中,文本文件中的行以rn序列结束,所以您的getline()函数似乎终止于n并返回r作为字符串。

总结

以上是内存溢出为你收集整理的_stricmp在string匹配时返回错误的值。 该怎么办?全部内容,希望文章能够帮你解决_stricmp在string匹配时返回错误的值。 该怎么办?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1282373.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存