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

    once more... read txt file

    Scheduled Pinned Locked Moved SDK Help
    13 Posts 0 Posters 987 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 15/05/2009 at 06:14, xxxxxxxx wrote:

      now i only need to know why i get those thrange cryptic bunch of chars between every char from the txt file??
      edit:
      i use SubStr to always just get the first char. that works here. is the code below save for different plattforms?

      > `

        
      \>  String GetfileContent(Filename fn)  
      \>  {  
      \>       AutoAlloc<BaseFile> bfile;  
      \>       LONG i = 0;  
      \>       String singleChar;  
      \>       String line = " ";  
      \>       CHAR c;  
      \>       CHAR* pc = &c;  
      \>       if(bfile->Open(fn, GE_READ, FILE_IGNOREOPEN, GE_MOTOROLA, MACTYPE_CINEMA, MACCREATOR_CINEMA))  
      \>       {  
      \>            VLONG fileLength = bfile->GetLength();  
      \>            while(i < fileLength)  
      \>            {  
      \>                 bfile->ReadChar(pc);  
      \>              singleChar = pc;  
      \>                 line = (line + singleChar.SubStr(0, 1));  
      \>                 i++;  
      \>            }  
      \>            bfile->Close();  
      \>       }  
      \>       else  
      \>       {  
      \>            line = "Error";  
      \>       }  
      \>       return line;  
      \>  }  
      \>  
      

      `

      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 15/05/2009 at 06:45, xxxxxxxx wrote:

        You can't do this type of assignment between the C4D SDK String class and CHAR*: singleChar = pc;

        A C/C++ 'string' (char array) needs to be Null terminated. Then you need to instantiate the String class with a constructor.

        What would work better here is to declare c as CHAR c[2], set c[1] = 0 (null terminate). Then do this:

        bfile->ReadChar(pc);
        line += String(pc);

        SubStr() is a long way to go to concatenate a single character into a string.

        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 15/05/2009 at 07:47, xxxxxxxx wrote:

          I should also note that in your situation, a for loop would be much more optimal than a while loop:

          for (i = 0L; i != fileLength; ++i)

          The for loop is more encapsulated, creating tighter, faster machine code than a while loop for simple incrementation.

          ETA: c[1] = 0; only has to be done once - outside of the loop.

          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 15/05/2009 at 09:00, xxxxxxxx wrote:

            thanks for your advice, when i do so, i get those cryptic characters in the console. thats why i used SubStr(0,1)..

            how do i get rid of them and get just the content of the txt file?

            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 15/05/2009 at 10:38, xxxxxxxx wrote:

              Two possibilities offhand:

              1. Might be control characters (tabs, carriage returns, etc.)? It may also be byte-order but that would be suspect for a non-binary text file.

              2. The file might not be plain ASCII? If the file is in UTF-16 or some other 'text' format using Unicode that would explain the characters. You would need to check for control sequences or read two chars at a time.

              Otherwise, a A+0 is "A" and a valid string (C/C++/C4DSDK). Have you tried simply printing GePrint(*pc) to see what values you are getting? (You could do some ASCII fix up here to get the character printed rather than the ASCII value.

              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 15/05/2009 at 11:29, xxxxxxxx wrote:

                Hm, the file is saved from windows notepad with ansi coding.. and the characters are just typed straight away, no tabs or anything ... just like "test123"

                here is the console output:
                console1.gif

                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 15/05/2009 at 13:11, xxxxxxxx wrote:

                  I would simply use the standard FILE struct and the functions fopen and fread from stdio.h. That also works on both, PC and MAC, without problems.

                  Greetings,
                  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 15/05/2009 at 13:59, xxxxxxxx wrote:

                    That's what I use. 🙂 Though these standard C file accessors are not Unicode/wide-character aware - if needed.

                    Let me run a simple test plugin to see what I get. Will make determination easier.

                    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 15/05/2009 at 14:19, xxxxxxxx wrote:

                      Try this instead:

                      > String GetFileContent(const Filename& fn) \> { \>      AutoAlloc<BaseFile> bfile; \>      if (!bfile) \>      { \>           MessageDialog("Test: BaseFile"); \>           return ""; \>      } \>      if (!bfile->Open(fn, GE_READ, FILE_IGNOREOPEN, GE_INTEL)) \>      { \>           MessageDialog("Test: bfile->Open"); \>           return ""; \>      } \>       \>      String line = ""; \>      LONG fileLength = bfile->GetLength(); \>      CHAR c[2]; \>      c[1] = 0; \>      CHAR\* pc = &c;[0]; \>      for (LONG i = 0L; i != fileLength; ++i) \>      { \>           bfile->ReadChar(pc); \>           // Line read from the file \>           line += String(pc); \>      } \>      GePrint(line); \>      bfile->Close(); \>      return line; \> }

                      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 15/05/2009 at 14:23, xxxxxxxx wrote:

                        An endian issue I think. If you run on Windows and use GE_MOTOROLA, the bits will be considered in the opposite order.

                        You can change those LONGs back to VLONGs. I did a quick build in VS6.0 for R9.1 (from a simple project).

                        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 15/05/2009 at 14:32, xxxxxxxx wrote:

                          thank you both.
                          robert, that indeed works!

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