[英]Why does my strcmp fail?
I am working on an application, where if this certain error message is given, it is ignored: 我正在处理一个应用程序,如果给出了这个特定的错误消息,它将被忽略:
[Oracle][ODBC][Ora]ORA-24338: statement handle not executed
[Oracle] [ODBC] [Ora] ORA-24338:语句句柄未执行
My code for comparison is the following: 我的比较代码如下:
char Sqlstate[10];
long NativeErrorPtr;
char MessageText[1024];
long BufferLength=1024;
long TextLengthPtr;
SQLGetDiagRec(SQL_HANDLE_STMT,sqlc.g_hstmt,1,(SQLCHAR *) Sqlstate,(SQLINTEGER *) &NativeErrorPtr,
(SQLCHAR *) MessageText,(SQLSMALLINT) BufferLength,(SQLSMALLINT *) &TextLengthPtr);
success=false;
char* msg = MessageText;
char* oracleMsg = "[Oracle][ODBC][Ora]ORA-24338: statement handle not executed";
int i = strcmp(msg, oracleMsg);
I am getting i ==1
. 我得到
i ==1
。 When I hover over both msg
and oracleMsg
they look exactly the same. 当我将鼠标悬停在
msg
和oracleMsg
它们看起来完全相同。 Here is the copied text from each variable. 这是每个变量的复制文本。
oracleMsg 0x00c1cd88 "[Oracle][ODBC][Ora]ORA-24338: statement handle not executed" char *
oracleMsg 0x00c1cd88“[Oracle] [ODBC] [Ora] ORA-24338:语句句柄未执行”char *
msg 0x0132d0a4 "[Oracle][ODBC][Ora]ORA-24338: statement handle not executed" char *
msg 0x0132d0a4“[Oracle] [ODBC] [Ora] ORA-24338:语句句柄未执行”char *
My problem must have been that it is not NULL-terminated. 我的问题一定是它没有以NULL结尾。 I followed ibre5041's advice and used
if((strncmp(msg, oracleMsg, 55))== 0)
. 我按照ibre5041的建议使用
if((strncmp(msg, oracleMsg, 55))== 0)
。 This only compares the first 55 characters, which avoids the non NULL-terminated issue. 这只比较前55个字符,这避免了非NULL终止的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.