tags:

views:

136

answers:

2

Hi

I am looking for a strcpy equivalent in Symbian. I do not wanna use the strcpy function from stdlib.

Here is what I wanna do:

char name[128];
TBuf8 aName = _L("Test");

strncpy( name, aName.Ptr(), 127 );
*( name + MAX_FILENAME_LEN ) = 0;

So basically I wanna copy a TBuf8 to an char array. Is there a proper way to do that in Symbian? aName has to be of type char!

Thanks

+1  A: 

Like this:

TInt size = aName.Size() <= 127 ? aName.Size() : 127;
Mem::Copy(name, aName.Ptr(), size);
name[size] = 0;

But beware that on unicode builds, TBuf8 strings are hard to come by, so there may be more to it than this.

Steve Jessop
+1  A: 
char name[128];
TBuf8 name_buf = _L("Test");
TPtr8 name_ptr = TPtr8(name,sizeof(name));
name_ptr = aName;
name_ptr.ZeroTerminate(); //if it supposed to be a zeroterminated string.

All text processing in symbian is easier if you learn to think in descriptors.

The ZeroTerminate call should obviously not be used if the TBuf8 contains binary data.

Ola