I always get a compiler error when I try what you did on #7. I always have to use s t r c p y / _ t c s c p y.
Can anyone show how to use squiggly brackets/braces to assign to T C H A R ?
I always get a compiler error when I try what you did on #7. I always have to use s t r c p y / _ t c s c p y.
Can anyone show how to use squiggly brackets/braces to assign to T C H A R ?
Do you understand regular C-strings and arrays? You don't use braces to assign to a TCHAR. You can use it to *initialize* an array of TCHAR, just like any other array, but you can't use it to *assign* to a TCHAR. You *must* use _tcscpy.
Show us exactly what you're trying to do that's failing.
Since you are just learning C, you really should forget about this TCHAR stuff.
Forget MSVC. Use CodeBlocks (with gcc) and spend a year learning the basics.
Then you'll be able to figure out the TCHAR thing yourself. At this point it's a waste of time.
The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss
Why is everyone not following.
The original question: please provide the many ways one can assign data (printable, hex, decimal) to a TCHAR (whether single-byte TCHAR or array) directly (and not via for loop or from any other source).
My program is already 1500 lines of code and will be around 5000 when complete. I have all my parsing routines complete (using TCHAR). I do NOT understand the syntax of assigning data TO a TCHAR other than simple 'x' or _T("longstring"). As I said, I had trouble assigning a 0xnnnnnnn value to a TCHAR. With the UNICODE compile option on (default), does TCHAR mandate a 2-byte hex field? Will it pad a 1-byte with 0x00?
I understand all the types of string data for Windows. But I do NOT understand the SYNTAX of how to do "tricky" (actually normal) things to them when it comes to assignment.
I already understand the internals of TCHARS. I do NOT fully understand the COMPILER SYNTAX of how to assign all the flavors of bits one can put in a TCHAR. Hence, my original post.
You don't need a year for the basics. It's only been a few weeks and the hardest part of the program is complete (all the parsing).
Because there are no other ways, you don't do that. TCHAR isn't a swiss army knife. If you want a type to hold a number, use 'int' or one of the myriad of other fixed size types to accommodate it. No, they wont make your program consume any more or less memory, and no they won't make your program any slower or faster.
I was using a single TCHAR field as holding bit settings for a function. I suppose I could use an int but it's counterintuitive to an assembler programmer to use a word/register to hold bit settings. I got the 0xnnn assignment to work, but always have to printf %x to see if it got stored as expected.....
>> I was using a single TCHAR field as holding bit settings for a function.
That's not what TCHAR is for. If you just want a type to store at least 8 bits, then use "unsigned char", or Window's BYTE type.
For hex values in character and string literals, you can use the '\x' escape sequence followed by a hex number. In a TCHAR literal, there should never be more than 2 hex digits. Eg: _T('\xff') is a single TCHAR with a value of 0xff. But this should never be needed in the first place.
I would be interested in knowing if your code compiles and runs correctly when you toggle the "Character Set" project-property in Visual Studio.
gg