Read-only archive of the All About Symbian forum (2001–2013) · About this archive

How to handle char array?

1 replies · 2,706 views · Started 04 October 2004

Hi ,
I have previously saved arrays of characters into a binary file from another C++ platform. I now wish to load up the data and use the char arrays. Since in Symbian, these are handled as descriptors, I am wondering how I could convert the char* ( bytes ) that I have in my data file into the TBufs or HBufs...

Most of the examples that I have come across deals with such descriptors with constant strings ... _LIT(KString,"blah blah blah"😉; ... I am at a lost at handling the char array that I have from my binary file.

Help... Advice... Solutions... will be appreciated.

I encountered this problem myself 1 day ago and this is my solution.
I want to build a HBufC (compatible with TDesC) from two string arrays
so my end result looks like "\t\Main label\tSecond label" for loading a double list

It might be possible to do it all better with the String class but I haven't tried yet.

void CDialGenieDoubleList::PopulateListFromCArraysL( CDesCArray& aListArray,
TInt aNumEntries, char * const aMainLabel[], char * const aSecondLabel[] )
{
HBufC* stringBuf = HBufC::NewLC(100);
TPtr stringAccess = stringBuf->Des();

_LIT (KTabChar, "\t" );

for (TInt i = 0; i < aNumEntries; i++)
{
stringAccess.Copy( KTabChar ); // String is now length 1

TInt j = 0;
while (aMainLabel[i][j] != '\0'😉
{
TInt Character = (TInt)aMainLabel[i][j++]; // Convert C char to int to TChar
stringAccess.Append( Character );
}

stringAccess += KTabChar;

j = 0;
while (aSecondLabel[i][j] != '\0'😉
{
TInt Character = (TInt)aSecondLabel[i][j++];
stringAccess.Append( Character );
}
// StringBuf now contains "\tMainLabel\tSecondLabel"

aListArray.AppendL (*stringBuf);
} // for (TInt i = 0; i < aNumEntries; i++)

CleanupStack::PopAndDestroy(stringBuf);
}