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. The Lounge
  3. (brain dead) How do you call text files with data stored with fixed width/length ?

(brain dead) How do you call text files with data stored with fixed width/length ?

Scheduled Pinned Locked Moved The Lounge
devopstutorialquestion
16 Posts 11 Posters 5 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.
  • M Maximilien

    I have a text file that stores data and each data is fixed size. I know that a name fiels is 10 caracters wide , and then the age is 3 caracters wide. For example (dot represent the end of line for clarity)

    Max 13 .
    Suzanne 34 .
    John Paul 66 .

    CI/CD = Continuous Impediment/Continuous Despair

    Mircea NeacsuM Online
    Mircea NeacsuM Online
    Mircea Neacsu
    wrote on last edited by
    #3

    File with fixed field records. They date back to at least FORTRAN where read (and write) statements had a “FORMAT” statement describing the “fields”. The easiest ones to write where those with fixed fields.

    Mircea

    1 Reply Last reply
    0
    • M Maximilien

      I have a text file that stores data and each data is fixed size. I know that a name fiels is 10 caracters wide , and then the age is 3 caracters wide. For example (dot represent the end of line for clarity)

      Max 13 .
      Suzanne 34 .
      John Paul 66 .

      CI/CD = Continuous Impediment/Continuous Despair

      J Offline
      J Offline
      Jeremy Falcon
      wrote on last edited by
      #4

      ^(.{1,10})(.*) Tada! That pattern has two capturing groups, with the first going to only 10 chars wide but while allowing spaces. Any regex engine will be able to get the matches. If you be in JavaScript then this is how you get the matches:

      const matches = /cool pattern/.exec(line input);
      if (matches) {
      // can access matches via index, you can trim any extra whitespace
      }

      Jeremy Falcon

      1 Reply Last reply
      0
      • M Maximilien

        I have a text file that stores data and each data is fixed size. I know that a name fiels is 10 caracters wide , and then the age is 3 caracters wide. For example (dot represent the end of line for clarity)

        Max 13 .
        Suzanne 34 .
        John Paul 66 .

        CI/CD = Continuous Impediment/Continuous Despair

        B Offline
        B Offline
        BernardIE5317
        wrote on last edited by
        #5

        C++ Standard Template Library makes it easy plus a few pesky details even w/o help from an AI agent.

        #include
        #include
        using namespace std;

        int main()
        {
        int lineBreakLength = 2;
        int nameFieldLength = 11;
        int ageFieldLength = 3;
        basic_ifstream _ifstream(L"text file.txt", ios_base::binary);
        char name[16]; name[nameFieldLength] = 0;
        char age[8]; age[ageFieldLength] = 0;
        char line_break[2];
        while(!_ifstream.eof())
        {
        _ifstream.read(name, nameFieldLength);
        _ifstream.read(age, ageFieldLength);
        cout << name << ' ' << age << endl;
        if(!_ifstream.eof()) _ifstream.read(line_break, lineBreakLength);
        }
        return 0;
        }

        "I must have had lessons." - Reverend Jim Ignatowski / Christopher Lloyd

        K J 2 Replies Last reply
        0
        • B BernardIE5317

          C++ Standard Template Library makes it easy plus a few pesky details even w/o help from an AI agent.

          #include
          #include
          using namespace std;

          int main()
          {
          int lineBreakLength = 2;
          int nameFieldLength = 11;
          int ageFieldLength = 3;
          basic_ifstream _ifstream(L"text file.txt", ios_base::binary);
          char name[16]; name[nameFieldLength] = 0;
          char age[8]; age[ageFieldLength] = 0;
          char line_break[2];
          while(!_ifstream.eof())
          {
          _ifstream.read(name, nameFieldLength);
          _ifstream.read(age, ageFieldLength);
          cout << name << ' ' << age << endl;
          if(!_ifstream.eof()) _ifstream.read(line_break, lineBreakLength);
          }
          return 0;
          }

          "I must have had lessons." - Reverend Jim Ignatowski / Christopher Lloyd

          K Offline
          K Offline
          k5054
          wrote on last edited by
          #6

          Except for the part where identifiers starting with _ are reserved for the implementation :(

          "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

          G 1 Reply Last reply
          0
          • M Maximilien

            I have a text file that stores data and each data is fixed size. I know that a name fiels is 10 caracters wide , and then the age is 3 caracters wide. For example (dot represent the end of line for clarity)

            Max 13 .
            Suzanne 34 .
            John Paul 66 .

            CI/CD = Continuous Impediment/Continuous Despair

            M Offline
            M Offline
            Marc Clifton
            wrote on last edited by
            #7

            Oh look, I'm using an archaic fixed length COBOL-style file format! How's that for the name? ;)

            Latest Articles:
            A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

            J 1 Reply Last reply
            0
            • M Maximilien

              I have a text file that stores data and each data is fixed size. I know that a name fiels is 10 caracters wide , and then the age is 3 caracters wide. For example (dot represent the end of line for clarity)

              Max 13 .
              Suzanne 34 .
              John Paul 66 .

              CI/CD = Continuous Impediment/Continuous Despair

              A Offline
              A Offline
              Amarnath S
              wrote on last edited by
              #8

              Maximilien wrote:

              Max 13

              Does that indicate your age? :-)

              1 Reply Last reply
              0
              • M Maximilien

                I have a text file that stores data and each data is fixed size. I know that a name fiels is 10 caracters wide , and then the age is 3 caracters wide. For example (dot represent the end of line for clarity)

                Max 13 .
                Suzanne 34 .
                John Paul 66 .

                CI/CD = Continuous Impediment/Continuous Despair

                C Offline
                C Offline
                CPallini
                wrote on last edited by
                #9

                :rolleyes:

                "In testa che avete, Signor di Ceprano?" -- Rigoletto

                M 1 Reply Last reply
                0
                • B BernardIE5317

                  C++ Standard Template Library makes it easy plus a few pesky details even w/o help from an AI agent.

                  #include
                  #include
                  using namespace std;

                  int main()
                  {
                  int lineBreakLength = 2;
                  int nameFieldLength = 11;
                  int ageFieldLength = 3;
                  basic_ifstream _ifstream(L"text file.txt", ios_base::binary);
                  char name[16]; name[nameFieldLength] = 0;
                  char age[8]; age[ageFieldLength] = 0;
                  char line_break[2];
                  while(!_ifstream.eof())
                  {
                  _ifstream.read(name, nameFieldLength);
                  _ifstream.read(age, ageFieldLength);
                  cout << name << ' ' << age << endl;
                  if(!_ifstream.eof()) _ifstream.read(line_break, lineBreakLength);
                  }
                  return 0;
                  }

                  "I must have had lessons." - Reverend Jim Ignatowski / Christopher Lloyd

                  J Offline
                  J Offline
                  Jeremy Falcon
                  wrote on last edited by
                  #10

                  I read it wrong at first too. But, he was asking what to call the file not how to read it. :laugh:

                  Jeremy Falcon

                  1 Reply Last reply
                  0
                  • M Marc Clifton

                    Oh look, I'm using an archaic fixed length COBOL-style file format! How's that for the name? ;)

                    Latest Articles:
                    A Lightweight Thread Safe In-Memory Keyed Generic Cache Collection Service A Dynamic Where Implementation for Entity Framework

                    J Offline
                    J Offline
                    Jeremy Falcon
                    wrote on last edited by
                    #11

                    How about we create a modern acronym for it.... FUBAR! Fixed-length Unicode Byte Array Record :rolleyes: :rolleyes:

                    Jeremy Falcon

                    1 Reply Last reply
                    0
                    • C CPallini

                      :rolleyes:

                      "In testa che avete, Signor di Ceprano?" -- Rigoletto

                      M Offline
                      M Offline
                      Maximilien
                      wrote on last edited by
                      #12

                      I'm sure they are direct descendant of punch cards. (large public sector system)

                      CI/CD = Continuous Impediment/Continuous Despair

                      1 Reply Last reply
                      0
                      • R RickZeeland

                        fixed-length text files: Process fixed-length text files with mapping data flows in Azure Data Factory - Azure Data Factory | Microsoft Learn[^] Or fixed-width text Files: How to: read from fixed-width text Files - Visual Basic | Microsoft Learn[^]

                        M Offline
                        M Offline
                        Maximilien
                        wrote on last edited by
                        #13

                        thanks.

                        CI/CD = Continuous Impediment/Continuous Despair

                        1 Reply Last reply
                        0
                        • K k5054

                          Except for the part where identifiers starting with _ are reserved for the implementation :(

                          "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

                          G Offline
                          G Offline
                          Gary Wheeler
                          wrote on last edited by
                          #14

                          FWIW, we've used leading underscores to mark private members as part of our coding conventions since the 1990's and never had an issue.

                          Software Zen: delete this;

                          K 1 Reply Last reply
                          0
                          • G Gary Wheeler

                            FWIW, we've used leading underscores to mark private members as part of our coding conventions since the 1990's and never had an issue.

                            Software Zen: delete this;

                            K Offline
                            K Offline
                            k5054
                            wrote on last edited by
                            #15

                            Fortunately, most implementations use a double underscore for system identifiers, so you're usually OK. But if you get strange error messages that refer to an identifier starting with an underscore, you've probably managed to collide with the compilers internals.

                            "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

                            A 1 Reply Last reply
                            0
                            • K k5054

                              Fortunately, most implementations use a double underscore for system identifiers, so you're usually OK. But if you get strange error messages that refer to an identifier starting with an underscore, you've probably managed to collide with the compilers internals.

                              "A little song, a little dance, a little seltzer down your pants" Chuckles the clown

                              A Offline
                              A Offline
                              Alister Morton
                              wrote on last edited by
                              #16

                              k5054 wrote:

                              you've probably managed to collide with the compilers internals

                              I was tearing my hair out once when I couldn't get a bit of financial code to compile - I had a variable called yield. Turns out there was a yield macro in the windows header to maintain compatibility with 16 bit windows. Sheesh.

                              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