Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. Read text file ??

Read text file ??

Scheduled Pinned Locked Moved Mobile
question
4 Posts 2 Posters 27 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dlhson2
    wrote on last edited by
    #1

    I have a text file abc.txt in Windows 2000, like that: "a b c", export it to emulator. Now I want to read it by these code: CFile f; CFileException e; PTCHAR szFileName= _T("abc.txt"); if (f.Open(szFileName,CFile::modeRead,&e)) { CString strText; TCHAR szChar[255]; UINT nRead=f.Read(szChar,2); if (SUCCEEDED(nRead)) { CString strMsg; strMsg.Format(_T("Read text: %s"),szChar); MessageBox(strMsg); } } But messagebox shows a strange string. It's not "a " as I thounght. Why ? ======================= Nothing is perfect

    D 1 Reply Last reply
    0
    • D dlhson2

      I have a text file abc.txt in Windows 2000, like that: "a b c", export it to emulator. Now I want to read it by these code: CFile f; CFileException e; PTCHAR szFileName= _T("abc.txt"); if (f.Open(szFileName,CFile::modeRead,&e)) { CString strText; TCHAR szChar[255]; UINT nRead=f.Read(szChar,2); if (SUCCEEDED(nRead)) { CString strMsg; strMsg.Format(_T("Read text: %s"),szChar); MessageBox(strMsg); } } But messagebox shows a strange string. It's not "a " as I thounght. Why ? ======================= Nothing is perfect

      D Offline
      D Offline
      Daniel Strigl
      wrote on last edited by
      #2

      First, I think that there is no 0 terminator at the end of the string (szRead[3] = _T('\0');)! Second, I think that in the ASCII file (abc.txt) there are no UNICODE characters, but in your Pocket PC application you read UNICODE characters (TCHAR's). Daniel ;) --------------------------- Never change a running system!

      D 1 Reply Last reply
      0
      • D Daniel Strigl

        First, I think that there is no 0 terminator at the end of the string (szRead[3] = _T('\0');)! Second, I think that in the ASCII file (abc.txt) there are no UNICODE characters, but in your Pocket PC application you read UNICODE characters (TCHAR's). Daniel ;) --------------------------- Never change a running system!

        D Offline
        D Offline
        dlhson2
        wrote on last edited by
        #3

        So how can I solve this problem ? ======================= Nothing is perfect

        D 1 Reply Last reply
        0
        • D dlhson2

          So how can I solve this problem ? ======================= Nothing is perfect

          D Offline
          D Offline
          Daniel Strigl
          wrote on last edited by
          #4

          If you have the following 3 characters abc in the file "abc.txt", try this:

          #include <atlbase.h> // need for A2CT macro

          CFile f;
          CFileException e;

          if (f.Open(_T("abc.txt"),CFile::modeRead,&e))
          {
          USES_CONVERSION; // need for A2CT macro

          char szChar\[255\] = { 0 };
          
          UINT nRead = f.Read(szChar,3); // Read the 3 characters 'abc'
          
          szChar\[nRead\] = '\\0'; // Add the NULL terminator
          
          CString strMsg;
          strMsg.Format(\_T("Read text: %s"), A2CT(szChar));  // Ansi --> UNICODE
          AfxMessageBox(strMsg);
          

          }

          Daniel ;) --------------------------- Never change a running system!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups