by fzammetti » Feb 20, 2004 @ 6:03pm
Strings actually bugged me a bit when I started C as well. Here's four things to remember that will probably make your life easier... they are things that have either bitten me at one time or another or that I've seen asked a number of times...
(1) You will want to use TCHAR's for PocketPC development most of the time because of it's unicode nature, and the functions that operate on these begin with _tcs (there could be a couple of exceptions, but this is a good starting point when your looking through the docs). The nice thing about this is that, assuming you use the TEXT("") macro (or _T I think is the same), your code will compile on the desktop and PocketPC without any problems.
(2) Remember that a TCHAR, or any other string for that matter, is just an array of some data type underneath it all. You can always do things like:
TCHAR myStr[25] = TEXT("My String");
someVar = myStr[5];
(3) ALWAYS remember to terminate your strings properly with \0! My understanding is that most if not all of the _tcs functions do this for you, which means you'll have to remember it when you size your strings, but if there's any doubt, do it yourself! You'd be surprised how many times this will save you hours of debugging, especially if your accessing the strings as an array in loops and such,
(4) Most of the time when you are calling on a function that accepts a TCHAR as an argument, you usually just pass the variable like so:
TCHAR myStr[25] = TEXT("My String");
someFunction(myStr);
But sometimes you'll find that won't compile. If it won't, try this:
someFunction(&myStr[0]);
That may save you some time one day when something isn't compiling properly, it's happened to me a number of times.
Hope this all helps!
...and so I said to Mr. Gates: "$640 billion should be enough for anyone!"