Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Read a text file

    Scheduled Pinned Locked Moved SDK Help
    3 Posts 0 Posters 343 Views
    Loading More Posts
    • 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.
    • H Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 20/11/2009 at 18:39, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   10/11 
      Platform:   Windows  ;   Mac OSX  ; 
      Language(s) :     C++  ;

      ---------
      Hi,

      I have some problems with a pretty simple task: Reading a text file and writing its contents into another file. Here's some code:

        
      void CopyA2B(BaseFile *source, BaseFile *target)   
      {   
           if (!source || !target) return;   
        
           CHAR c;   
           String cs = String();   
           String Content = String();   
           VLONG length = source->GetLength();   
        
           for (VLONG i = 0; i < length; i++) {   
                source->ReadChar(&c;);   
                cs.SetCString(&c;);   
                Content = Content + cs;   
           }   
           // WriteString() function posted in C4Dcafé by Matthias Bober   
           // It works fine, so the problem must be the reading   
           WriteString(Content, target);   
      }   
      

      The strange thing is, that - no matter which StringEncoding I use in SetCString() - I end up with something that looks like this:

      b\u00CC\u00CC\u00CCo\u00CC\u00CC\u00CCd\u00CC\u00CC\u00CCy\u00CC\u00CC\u00CC \u00CC\u00CC\u00CC{\u00CC\u00CC\u00CC
      \u00CC\u00CC\u00CC
      \u00CC\u00CC\u00CC     \u00CC\u00CC\u00CCb\u00CC\u00CC\u00CCa\u00CC\u00CC\u00CCc\u00CC\u00CC\u00CCk\u00CC\u00CC\u00CCg\u00CC\u00CC\u00CCr\u00CC\u00CC\u00CCo\u00CC\u00CC\u00CCu\u00CC\u00CC\u00CCn\u00CC\u00CC\u00CCd\u00CC\u00CC\u00CC-\u00CC\u00CC\u00CCc\u00CC\u00CC\u00CCo\u00CC\u00CC\u00CCl\u00CC\u00CC\u00CCo\u00CC\u00CC\u00CCr\u00CC\u00CC\u00CC:\u00CC\u00CC\u00CC#\u00CC\u00CC\u00CCA\u00CC\u00CC\u00CCA\u00CC\u00CC\u00CCA\u00CC\u00CC\u00CCA\u00CC\u00CC\u00CCA\u00CC\u00CC\u00CCA\u00CC\u00CC\u00CC;\u00CC\u00CC\u00CC
      \u00CC\u00CC\u00CC
      \u00CC\u00CC\u00CC}\u00CC\u00CC\u00CC

      How can I simply read a text file using the BaseFile class and get the file contents as a String?

      Thanks in advance 🙂

      Cheers,
      Jack

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 21/11/2009 at 03:23, xxxxxxxx wrote:

        Originally posted by xxxxxxxx

        User Information:
        Cinema 4D Version:   10/11 
        Platform:   Windows  ;  
        Mac OSX  ; 
        Language(s) :    
        C++  ;

        ---------
           Hi,

        I have some problems with a pretty simple task: Reading a text file and writing its contents into another file. Here's some code:

        Looking at the output (it is the typical pattern of an uninitialized memory block), I assume your source->ReadChar() returned an error (you didn't check for success after calling the function) for whatever reason.

        Best regards,

        Wilfried Behne

        Btw.: Your read loop is not that efficient. Every String addition/SetCString will create/release memory blocks.

        Think about reading a larger chunk of bytes into a buffer and convert them with one call...

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 21/11/2009 at 03:34, xxxxxxxx wrote:

          Thanks. Did that and it works now 🙂

          Cheers,
          Jack

          1 Reply Last reply Reply Quote 0
          • First post
            Last post