I appreciate any help ........I treid many solution it did not work!

aTree.AddString(L"barak");

//this is working 100%

when I tried to do this :

char *p; 
      p = new char[500];

      //read the value of p from file one line at a time

      aTree.AddString(p);//not working

You'll have to elaborate a little. "It's not working" gives us nothing to go on. Are you getting a compiler error, invalid output, etc...?

What is the definition of "AddString()"?

The first works ok because L converts a string literal from char* to wcar_t*. The second doesn't work because it is attempting to pass char* to a function that expects wchar_t*, and typecasting will ont convert that either.

Read this article

CSuffixTrie aTree;
char *p;      
p = new char[500];
//read the value of p from file one line at a time
 aTree.AddString(p);//not workingchar

this is the CSuffixTrie defenition

#include "stdafx.h"
#include "SuffixTrie.h"

CSuffixTrie::CSuffixTrie()
{
	//Init the root node
	m_aRoot.pFailureNode=NULL;
	m_aRoot.aChar=0;
	m_aRoot.bFinal=false;
	m_aRoot.usDepth=0;
}

CSuffixTrie::CSuffixTrie(const CSuffixTrie& rTrie)
{
	//Clone to here
	rTrie.CloneTrie(*this);
}

CSuffixTrie::~CSuffixTrie()
{
	//Delete the tree
	Clear();
}

void CSuffixTrie::Clear()
{
	DeleteNode(&m_aRoot);
}

CSuffixTrie& CSuffixTrie::operator=(const CSuffixTrie& rTrie)
{
	//Sanity check
	if (this==&rTrie)
		return *this;

	//Close ourselves first
	rTrie.CloneTrie(*this);

	//Done
	return *this;
}

void CSuffixTrie::CloneTrie(CSuffixTrie& rTarget)const
{
	//First delete the other trie
	rTarget.Clear();

	//Do a clone
	Node* pClone;
	pClone=CloneNode(&m_aRoot);

	//Save it
	rTarget.m_aRoot=*pClone;

	//Renormalize it
	rTarget.BuildTreeIndex();

	//And delete that node
	delete pClone;
}

void CSuffixTrie::AddString(const SearchString& rString)
{
	//Add the string
	AddString(rString,
			  &m_aRoot);
}

void CSuffixTrie::AddString(const SearchString& rString,
						    Node* pNode)
{
	//Sanity check
	if (!pNode ||
		rString.empty())
		return;

	//The char we are looking for
	SearchChar aChar;
	aChar=rString[0];

	//Look for the next node
	SearchMap::iterator aIterator;
	aIterator=pNode->aMap.find(aChar);

	//Our node
	Node* pNewNode;

	//Do we have it?
	if (aIterator==pNode->aMap.end())
	{
		//Need to build this node
		pNewNode=new Node;

		//Reset it
		pNewNode->pFailureNode=NULL;
		pNewNode->aChar=aChar;
		pNewNode->usDepth=pNode->usDepth+1;
		pNewNode->bFinal=false;

		//Add it
		pNode->aMap.insert(SearchMap::value_type(aChar,pNewNode));
	}
	else
		//Take the node
		pNewNode=aIterator->second;

	//Is it the last char?
	if (rString.length()==1)
		//Set as last
		pNewNode->bFinal=true;
	else
		//Run next layer
		AddString(rString.substr(1,rString.length()-1),
				  pNewNode);
}

This is the error :

error C2664: 'void CSuffixTrie::AddString(const CSuffixTrie::SearchString &)' : cannot convert parameter 1 from 'char *' to 'const CSuffixTrie::SearchString &'

"The first works ok because L converts a string literal from char* to wcar_t*. The second doesn't work because it is attempting to pass char* to a function that expects wchar_t*, and typecasting will ont convert that either.
Read this article "


Thank you for your reple I tried the code , i get no error but no result also, the program terminate without any result, it Just asked me for the input file then terminat !
Do you think this is because p is not a char* its array of char*?

Post the newes code attempt because I can't see your monitor.

This is the code after the modifications

while(!inFile1.eof())
		  { 		
			 getline(inFile1, line);
			 char *p; 
			 p = new char[500];
			strcpy_s(p, 50, line.c_str());
			char *pp;
			pp = new char[500];
			strcpy_s(pp, 500, line.c_str());
			parseString(pp, p);
			//cout<<p<<endl;;

   
  //           Convert to a wchar_t*
             size_t origsize = strlen(p) + 1;
             const size_t newsize = 100;
             size_t convertedChars = 0;
             wchar_t wcstring[newsize];
             mbstowcs_s(&convertedChars, wcstring, origsize, p, _TRUNCATE);
             wcscat_s(wcstring, L" (wchar_t *)");
            
	     aTree.AddString(wcstring );

1. There appears to be a huge memory leak in that code -- when are p and pp deleted

2. Suggest you declare p, pp and wcstring higher up in the program, up above the beginning of that while loop. That way they are allocated just once during the lifetime of the program instead of on each iteration of that while loop. That will make your program run a bit faster too.


3. Are you sure there is enough roon left in wcstring to add that additional amount of characters on line 20?

3. That while loop is constructed incorrectly because eof() doesn't work that way. This is how to write the loop while( getline(inFile1, line) ) 4. Use your compiler's debugger to find out what is causing the program to crash. Other than the above comments your program looks normal to me.

Its still not working ......... !!!!!!!

This code perform the conversion and may solve the problem, but what library I need to run this code

// --------------------------------------------------------------------
// Convert 16bits UCS2 unicode data char* into HBufC16*
// --------------------------------------------------------------------
HBufC16* ConvertPCharToHBufC16L( char* aData )
{
if ( aData )
{
TInt length = User::StringLength( ( TUint8* )aData ) + 2;
TPtrC8 ptr( ( TText8* )aData );
HBufC* epoc_string = HBufC::NewL( length ); 
epoc_string->Des().Copy( ptr );
return epoc_string;
}
else
return NULL;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.