PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Reading text from a file using evc++ 3

Hi all, what's a good method for reading from a text file into a string, or set of strings?

I'd like to be able to run this using GapiDraw from a stationary machine (compiled under VC6.0) for build testing, and also on pocket pc's as the final target machine.

I'm getting terribly confused trying to use fopen, and failing due to lack of unicode between compilers, etc.
Well, the UNICODE involves two issues in your case. Whether or not the filename you wish to access is in unicode, and whether or not you want to load strings out of the file into UNICODE. The latter depends on what you want you are going to do with the strings you read. If they will be used with Windows GUI at all (filling edit boxes, list boxes, etc) then you should load them into UNICODE strings, because the Windows API requires UNICODE strings. Otherwise you don't need to use UNICODE if you don't want to support other character sets in the future.

To provide actual source code I would need to know more about what you are doing. Are you parsing strings? Is your data formatted? Is it just one big block of text? Where are you getting your filename from, and is it UNICODE or ANSI?

Regarding building the same source code for PC and Windows CE, you have to watch your "T" types. TCHAR, LPCTSTR, LPTSTR, _T(""), _TEXT("") and all other T strings' actual type is determined by whether or not UNICODE is defined. If UNICODE is defined then all the T types are WCHAR, or shorts (2 bytes per character). Otherwise they are just char types. So when you use any of the above types you must use the T type functions to go along with it. For example to compare two TCHAR strings you would use _tcscmp. To copy _tcscpy, etc. Otherwise it will build properly for UNICODE but not for non-UNICODE or vice-versa. If you want to use UNICODE no matter what then use W types like WCHAR, _wcscpy, etc. For ANSI only use the standard char, strcpy, strcmp, etc. The problem you have is when you mix and match one string type with functions designed to handle a different type.

Dan East
serenity · 06 Nov 2002, 08:47 UTC — thanks a lot
Thanks heaps, digesting everything :)