本文介绍了无法检索“const char *”的内容,因为它自身变空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我遇到这个问题,我有 const char * Decrypted_Message2 ,其中包含证书,浏览器现时和服务器现时(由分隔符分隔)。

我有这个功能,使用分隔符,字符单独拆分它们。我想要将第二个和第三个项目检索到数组中。

首先它工作正常,我得到浏览器nonce,称为Recovered_Browser_Nonce_from_Message2 。但是当我再次调用split函数来获取服务器nonce Recovered_Server_Nonce_from_Message2时,我发现Decrypted_Message是空的!!!!!!





Hi,

I'm having this problem, where I have this const char * Decrypted_Message2 that contains a certificate, browser nonce, and a Server Nonce (Separated by a delimiter ,).
I have this function that split them individually, using the delimiter "," character. And I want to retrieve the second and third items into the Array.
At first it works fine and I get the browser nonce, which is called "Recovered_Browser_Nonce_from_Message2 ". But then when I call the split function again to get the server nonce "Recovered_Server_Nonce_from_Message2", I find that the "Decrypted_Message" is empty!!!!!!


const char * Decrypted_Message2 = Decrypt_Message2(encrypted_message2, Shared_Session_Key_C );
	cout<<"\n\nDECRYPTED MESSAGE2 {S,nb,ns}:  "<<Decrypted_Message2;



const char * Recovered_Browser_Nonce_from_Message2 = Split_Server_Message2(Decrypted_Message2, true);
	cout<<"\n\nRECOVERED_BROWSER_NONCE:"<<Recovered_Browser_Nonce_from_Message2;
	cout<<"\n\ndecrypted message2:"<<Decrypted_Message2; //HERE IS WHERE I FIND IT EMPTY

const char * Recovered_Server_Nonce_from_Message2 = Split_Server_Message2(Decrypted_Message2, false);
	 cout<<"\nRECOVERED SERVER NONCE:  "<<Recovered_Server_Nonce_from_Message2;





以下是拆分功能:





the following is the split function:

const char * Client_Side::Split_Server_Message2(CkString Recieved_Message2_from_Server, bool flag)
{
	const char * Recovered_nb = "";
	const char * Recovered_ns = "";
	bool exceptDoubleQuoted = true;
	bool exceptEscaped = true;	// Do not treat characters preceded with a backslash as a delimiter.
	bool keepEmpty = false;	// Do not keep empty fields.
	char delimiter = ',';

	CkStringArray *array = Recieved_Message2_from_Server.split(delimiter,exceptDoubleQuoted,exceptEscaped,keepEmpty);


	if(flag == true)
	  {
	   for (int i=0; i<array->get_Count(); i++)
		{
		  array->getString(i);
		  //printf("%d: [%s]\n",i,array->getString(i));
		  Recovered_nb =  array->getString(1);  //Browser Nonce (nb)
		}
	   return Recovered_nb;
	  }


	else
	  {
		  for (int j=0; j<array->get_Count(); j++)
		{
		  array->getString(j);
		  //printf("%d: [%s]\n",j,array->getString(j));
		  Recovered_ns =  array->getString(2);     //Server Nonce (ns);
		}
		return Recovered_ns;
	  }

}





我这两天来一直在努力解决这个问题,我似乎无法找到问题!!!!

有人可以帮我这个。



问候。

Rania



我的尝试:



1-我已经尝试将Decrypted_Message2复制到另一个字符串中,它也不起作用。

我甚至尝试编写另一个拆分函数,只检索第三个项目,但它没有工作。



I've been struggling with this issue for two whole days now, and I cant seem to find the problem!!!!
Can someone please help me with this.

Regards.
Rania

What I have tried:

1- I've tried copying the "Decrypted_Message2" into another string, it didn't work either.
I even tried writing another "split" function, only to retrieve the third item, but it didn't work.

推荐答案

引用:

注意:应用程序负责删除(通过C ++删除操作符)此方法返回的对象。

Note: The application is responsible for deleting (via the C++ delete operator) the object returned by this method.



尝试使用此代码而不使用其他代码split函数(我在这里使用了短变量名):


Try this code instead which does not use an additional split function (I have used short variable names here):

// Copy message to a CkString.
CkString msg;
msg.SetString(Decrypted_Message2);
// Split it.
CkStringArray *array = msg.split(',', true, true, false);
// Get pointers to items checking if they exist.
//const char *cert = array->GetCount() > 0 ? array->GetString(0) : "";
const char *nb = array->GetCount() > 1 ? array->GetString(1) : "";
const char *ns = array->GetCount() > 2 ? array->GetString(2) : "";
// Use [cert,] nb, and ns here

// Delete array when finished using it.
delete array;


这篇关于无法检索“const char *”的内容,因为它自身变空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 03:31