Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

PCSTRING data type conversion

Featured Replies

Hi,Do you C++ experts know whether it is possible to convert regular variable values (ie of type int, float, string, etc) into a PCSTRINGZ data type and vice versa, in Visual C++?. As it is a typedef struct, I cannot find a way to do a direct conversion, and I'm not good with pointers' manipulation (yet).ThanksTom

Well, as the name PCSTRINGZ implies, this is a pointer to a string (to be more accurate, its a const pointer to a STRINGZ, which is just another name for a TCHAR array). You couldn't just convert ints or floats to this type, you would need to allocate a TCHAR buffer, use some printf or FormatString type api to convert your data to a string and then pass the TCHAR buffer.

  • Commercial Member

Ok... quick lesson. ;)char stringVariable[10]; // <-- an array of characters, up to 9 with a terminating zero value.char* pstringVariable; // <-- a pointer to a memory location that contains an array of characters, terminated with a zero value.char *pstringVariable; // <-- the exact same as above.PCSTRINGZ pstringVariable; // <-- the exact same as above.pstringVariable = (PCSTRINGZ)malloc(21); <-- allocates the memorysprintf(pstringVariable,"%1.0f",22.0); <-- formats the value of 22.0 into the pstringVariable character array.

Ed Wilson

Mindstar Aviation
My Playland - I69

  • Author

Hi Ed,Thank you for the example. Now one extra basic question :-)I have int a = 20 (or INT32, UINT32, etc)int b = 30 (or FLOAT64, etc)char Text[7]="Pointer"Now I want to make an array that holds "2030Pointer" and be of type PCSTRINGZ, for example PCSTRINGZ psvalue, where psvalue holds "2030Pointer".....???Tom

  • Commercial Member

>Hi Ed,>>Thank you for the example. >Now one extra basic question :-)>>I have >>int a = 20 (or INT32, UINT32, etc)>int b = 30 (or FLOAT64, etc)>>char Text[7]="Pointer">>Now I want to make an array that holds "2030Pointer" and be of>type PCSTRINGZ, for example PCSTRINGZ psvalue, where psvalue>holds "2030Pointer".....???>>Tom>>>>Ok... then do this:PCSTRINGZ mystringPtr;mystringPtr = (PCSTRINGZ)malloc(128); // <-- 128 bytes, plenty of room for what you want.sprintf(mystringPtr,"%d%d%s",a,b,Text);Just remember... if you allocate memory... deallocate it when done:delete(mystringPtr);

Ed Wilson

Mindstar Aviation
My Playland - I69

  • Author

Thank you Ed, Actually I don't want to output mystringPtr to the console, but rather hold a+b+Text "inside" mystringPtr and be able to pass mystringPtr as an argument of a function like MyFunct(PCSTRING mystringPtr, etc, etc).Anyway I have a good start point, will do some testings and see if I can nail it down.Thanks againTom

  • Author

Yes, you're right Ed, I confused printf with sprintf...Now I have it working like a charm, not like your example but in the inverse way:sprintf(mystringPtr,"%d%d%s",a,b,Text) doesn't work because sprintf cannot convert the PCSTRINGZ format to the char* format supported in the first parameter. Working with a char type and assigning the result to a PCSTRINGZ does the trick:int a = 5;int b = 23;char pMyBuffer[10]; sprintf_s(pMyBuffer,"%d%d%s",a,b,"1234567");PCSTRINGZ mystringPtr = pMyBuffer;now I have "5231234567" in mystringPtr, and no need to alloc/dealloc memory.Thank you very much for your help!Tom

  • Author

Yeah, maybe, but it happens that I'm still in "pre-basic" stages. Anyway I have plans to improve quickly...:-)Tom

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.