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. General Programming
  3. C / C++ / MFC
  4. Manipulating of .txt file

Manipulating of .txt file

Scheduled Pinned Locked Moved C / C++ / MFC
c++comhelpquestionlearning
9 Posts 3 Posters 0 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.
  • A Offline
    A Offline
    Artur Grabowski
    wrote on last edited by
    #1

    Welcome guys!!! I am a beginner in C++ and I have a little task to solve. Ihave a file .txt like this : net.txt - Google Drive[^] And i want make tables that for each number gives all value about the nuber from data Something like this :

    Number9
    from value
    1 0,70606
    3 0,99605
    11 -0,28155
    12 0,58371
    15 0,70069
    17 -0,95633
    18 0,84633
    19 0,77246
    25 0,49101
    30 -0,76256
    31 0,77975
    34 0,73573
    44 -0,6106
    45 -0,91379
    51 0,25814
    53 -0,59725
    54 -0,78294
    58 0,13108
    70 -0,02528
    73 0,37034
    75 0,23552
    76 -0,54187
    78 0,77419
    79 0,4681
    80 -0,01923
    83 0,39902
    85 0,82687

    I will be grateful for help or advices Thanks !!!!

    Richard Andrew x64R D 2 Replies Last reply
    0
    • A Artur Grabowski

      Welcome guys!!! I am a beginner in C++ and I have a little task to solve. Ihave a file .txt like this : net.txt - Google Drive[^] And i want make tables that for each number gives all value about the nuber from data Something like this :

      Number9
      from value
      1 0,70606
      3 0,99605
      11 -0,28155
      12 0,58371
      15 0,70069
      17 -0,95633
      18 0,84633
      19 0,77246
      25 0,49101
      30 -0,76256
      31 0,77975
      34 0,73573
      44 -0,6106
      45 -0,91379
      51 0,25814
      53 -0,59725
      54 -0,78294
      58 0,13108
      70 -0,02528
      73 0,37034
      75 0,23552
      76 -0,54187
      78 0,77419
      79 0,4681
      80 -0,01923
      83 0,39902
      85 0,82687

      I will be grateful for help or advices Thanks !!!!

      Richard Andrew x64R Offline
      Richard Andrew x64R Offline
      Richard Andrew x64
      wrote on last edited by
      #2

      Artur Grabowski wrote:

      I will be grateful for help or advices

      We're willing to help with good advice. But you need to ask a specific question. What have you tried? Where does it go wrong? Are there any error messages? Post a snippet of the text file you're using and the relevant portion of your code.

      The difficult we do right away... ...the impossible takes slightly longer.

      A 1 Reply Last reply
      0
      • Richard Andrew x64R Richard Andrew x64

        Artur Grabowski wrote:

        I will be grateful for help or advices

        We're willing to help with good advice. But you need to ask a specific question. What have you tried? Where does it go wrong? Are there any error messages? Post a snippet of the text file you're using and the relevant portion of your code.

        The difficult we do right away... ...the impossible takes slightly longer.

        A Offline
        A Offline
        Artur Grabowski
        wrote on last edited by
        #3

        i was trying but the problem is the parsing of uploaded file :/ in example :

        connection definition section :

        target site source:weight
        1 2: 0.00000, 3: 0.00000, 4: 0.00000, 5: 0.00000, 6: 0.00000, 7: 0.00000, 8: 0.00000, 9: 0.70606,
                     10: 0.00000,  11: 0.00000,  12: 0.00000,  13: 0.00000,  14: 0.00000,  15: 0.00000,  16:-0.38621,  17: 0.00000,
                     18: 0.00000,  19: 0.00000,  20: 0.00000,  21: 0.00000,  22: 0.00000,  23: 0.00000,  24: 0.00000,  25: 0.00000,
                     26: 0.00000,  27:-0.51685,  28: 0.00000,  29: 0.00000,  30: 0.00000,  31: 0.65813,  32: 0.00000,  33: 0.00000,
                     34: 0.00000,  35: 0.00000,  36:-0.23965,  37: 0.00000,  38: 0.00000,  39: 0.00000,  40:-0.53012,  41: 0.00000,
                     42: 0.65078,  43: 0.00000,  44:-0.25587,  45: 0.61060,  46:-0.77841,  47:-0.10781,  48: 0.00000,  49: 0.00000,
                     50: 0.00000,  51: 0.60152,  52:-0.04528,  53: 0.00000,  54: 0.00000,  55: 0.00000,  56: 0.34451,  57: 0.00000,
                     58:-0.63902,  59: 0.00000,  60: 0.00000,  61: 0.00000,  62: 0.00000,  63: 0.00000,  64: 0.00000,  65: 0.00000,
                     66:-0.35604,  67:-0.65445,  68: 0.00000,  69:-0.18092,  70: 0.00000,  71: 0.00000,  72: 0.00000,  73:-0.07051,
                     74: 0.00000,  75: 0.00000,  76: 0.62501,  77: 0.00000,  78:-0.66639,  79: 0.00000,  80: 0.00000,  81: 0.00000,
                     82: 0.54643,  83: 0.00000,  84: 0.86970,  85: 0.00000,  86: 0.00000,  87: 0.00000,  88: 0.17621,  89: 0.00000,
                     90: 0.00000,  91: 0.00000,  92: 0.00000,  93: 0.00000,  94: 0.00000,  95:-0.48619,  96:-0.21145,  97:-0.67891,
                     98: 0.00000,  99: 0.70803, 100:-0.94970, 101: 1.00000, 102: 1.00000, 103: 1.00000, 104: 1.00000, 105: 1.00000,
                    106: 1.00000, 107: 1.00000, 108: 1.00000, 109: 1.00000
         2 |      |   1: 0.00000,   3: 0.00000,   4:-0.70584,   5: 0.00000,   6: 0.00000,   7: 0.00000,   8: 0.73104,   9: 0.00000,
                     10:-0.68872,  11: 0.00000,  12:-0.06770,  13: 0.00000,  14: 0.00000,  15: 0.00000,  16:-0.51967,  17: 0.00000,
                     18: 0.17679,  19: 0.00000,  20: 0.00000,  21: 0.00000,  22: 0.00000,  23: 0.97774,  24: 0.00000,  25: 0.00000,
                     26:-0.53439,  27: 0.00000,  28: 0.00000,  29: 0.00000,  30: 0.00000,  31:-0.36626,  32: 0.00000,  33:-0.55026,
        
        Richard Andrew x64R 1 Reply Last reply
        0
        • A Artur Grabowski

          i was trying but the problem is the parsing of uploaded file :/ in example :

          connection definition section :

          target site source:weight
          1 2: 0.00000, 3: 0.00000, 4: 0.00000, 5: 0.00000, 6: 0.00000, 7: 0.00000, 8: 0.00000, 9: 0.70606,
                       10: 0.00000,  11: 0.00000,  12: 0.00000,  13: 0.00000,  14: 0.00000,  15: 0.00000,  16:-0.38621,  17: 0.00000,
                       18: 0.00000,  19: 0.00000,  20: 0.00000,  21: 0.00000,  22: 0.00000,  23: 0.00000,  24: 0.00000,  25: 0.00000,
                       26: 0.00000,  27:-0.51685,  28: 0.00000,  29: 0.00000,  30: 0.00000,  31: 0.65813,  32: 0.00000,  33: 0.00000,
                       34: 0.00000,  35: 0.00000,  36:-0.23965,  37: 0.00000,  38: 0.00000,  39: 0.00000,  40:-0.53012,  41: 0.00000,
                       42: 0.65078,  43: 0.00000,  44:-0.25587,  45: 0.61060,  46:-0.77841,  47:-0.10781,  48: 0.00000,  49: 0.00000,
                       50: 0.00000,  51: 0.60152,  52:-0.04528,  53: 0.00000,  54: 0.00000,  55: 0.00000,  56: 0.34451,  57: 0.00000,
                       58:-0.63902,  59: 0.00000,  60: 0.00000,  61: 0.00000,  62: 0.00000,  63: 0.00000,  64: 0.00000,  65: 0.00000,
                       66:-0.35604,  67:-0.65445,  68: 0.00000,  69:-0.18092,  70: 0.00000,  71: 0.00000,  72: 0.00000,  73:-0.07051,
                       74: 0.00000,  75: 0.00000,  76: 0.62501,  77: 0.00000,  78:-0.66639,  79: 0.00000,  80: 0.00000,  81: 0.00000,
                       82: 0.54643,  83: 0.00000,  84: 0.86970,  85: 0.00000,  86: 0.00000,  87: 0.00000,  88: 0.17621,  89: 0.00000,
                       90: 0.00000,  91: 0.00000,  92: 0.00000,  93: 0.00000,  94: 0.00000,  95:-0.48619,  96:-0.21145,  97:-0.67891,
                       98: 0.00000,  99: 0.70803, 100:-0.94970, 101: 1.00000, 102: 1.00000, 103: 1.00000, 104: 1.00000, 105: 1.00000,
                      106: 1.00000, 107: 1.00000, 108: 1.00000, 109: 1.00000
           2 |      |   1: 0.00000,   3: 0.00000,   4:-0.70584,   5: 0.00000,   6: 0.00000,   7: 0.00000,   8: 0.73104,   9: 0.00000,
                       10:-0.68872,  11: 0.00000,  12:-0.06770,  13: 0.00000,  14: 0.00000,  15: 0.00000,  16:-0.51967,  17: 0.00000,
                       18: 0.17679,  19: 0.00000,  20: 0.00000,  21: 0.00000,  22: 0.00000,  23: 0.97774,  24: 0.00000,  25: 0.00000,
                       26:-0.53439,  27: 0.00000,  28: 0.00000,  29: 0.00000,  30: 0.00000,  31:-0.36626,  32: 0.00000,  33:-0.55026,
          
          Richard Andrew x64R Offline
          Richard Andrew x64R Offline
          Richard Andrew x64
          wrote on last edited by
          #4

          Artur Grabowski wrote:

          the problem is the parsing of uploaded file

          That's what I was trying to get at. What EXACTLY is the problem?

          The difficult we do right away... ...the impossible takes slightly longer.

          A 1 Reply Last reply
          0
          • Richard Andrew x64R Richard Andrew x64

            Artur Grabowski wrote:

            the problem is the parsing of uploaded file

            That's what I was trying to get at. What EXACTLY is the problem?

            The difficult we do right away... ...the impossible takes slightly longer.

            A Offline
            A Offline
            Artur Grabowski
            wrote on last edited by
            #5

            I don't know how place data in right side

            Richard Andrew x64R 1 Reply Last reply
            0
            • A Artur Grabowski

              I don't know how place data in right side

              Richard Andrew x64R Offline
              Richard Andrew x64R Offline
              Richard Andrew x64
              wrote on last edited by
              #6

              I'm afraid that's not a good enough explanation of the problem you are facing to give you a good answer. Is the problem that you have no idea how to begin? In that case it will be difficult to help, because we can't teach you programming from scratch. Why don't you post what code you have so far.

              The difficult we do right away... ...the impossible takes slightly longer.

              A 1 Reply Last reply
              0
              • Richard Andrew x64R Richard Andrew x64

                I'm afraid that's not a good enough explanation of the problem you are facing to give you a good answer. Is the problem that you have no idea how to begin? In that case it will be difficult to help, because we can't teach you programming from scratch. Why don't you post what code you have so far.

                The difficult we do right away... ...the impossible takes slightly longer.

                A Offline
                A Offline
                Artur Grabowski
                wrote on last edited by
                #7

                QMap< int, QMap >::iterator it;
                it=targets->begin();
                while(it!=targets->end())
                {
                QString mod=" ";
                mod.append(QString::number(it.key())+" | | ");

                    int rowfillcount=0;
                    QMap::iterator it2=it.value().end();
                    do
                    {
                        --it2;
                
                        mod.append(QString("  ")+QString::number(it2.key())+":"+QString::number(it2.value(),'d',5)+",");
                
                        if(++rowfillcount==8)
                        {
                            rowfillcount=0;
                            mod.append("\\n                 ");
                        }
                    }
                    while(it2!=it.value().begin());
                
                    mod\[mod.lastIndexOf(",")\]='\\n';
                
                    ui->plainTextEdit\_result->appendPlainText(
                    mod);
                
                    it++;
                }
                
                ui->plainTextEdit\_result->appendPlainText(
                "-------|------|----------------------------------------------------------------------------------------------------------------\\
                
                1 Reply Last reply
                0
                • A Artur Grabowski

                  Welcome guys!!! I am a beginner in C++ and I have a little task to solve. Ihave a file .txt like this : net.txt - Google Drive[^] And i want make tables that for each number gives all value about the nuber from data Something like this :

                  Number9
                  from value
                  1 0,70606
                  3 0,99605
                  11 -0,28155
                  12 0,58371
                  15 0,70069
                  17 -0,95633
                  18 0,84633
                  19 0,77246
                  25 0,49101
                  30 -0,76256
                  31 0,77975
                  34 0,73573
                  44 -0,6106
                  45 -0,91379
                  51 0,25814
                  53 -0,59725
                  54 -0,78294
                  58 0,13108
                  70 -0,02528
                  73 0,37034
                  75 0,23552
                  76 -0,54187
                  78 0,77419
                  79 0,4681
                  80 -0,01923
                  83 0,39902
                  85 0,82687

                  I will be grateful for help or advices Thanks !!!!

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #8

                  Artur Grabowski wrote:

                  And i want make tables that for each number gives all value about the nuber from data

                  You do realize that you are the only one that understands this statement, don't you? How do the contents of the file "map" to your desired output?

                  Artur Grabowski wrote:

                  I will be grateful for help or advices

                  Put your keyboard away. What does "parsing the file" look like using paper and pencil?

                  "One man's wage rise is another man's price increase." - Harold Wilson

                  "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                  "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                  A 1 Reply Last reply
                  0
                  • D David Crow

                    Artur Grabowski wrote:

                    And i want make tables that for each number gives all value about the nuber from data

                    You do realize that you are the only one that understands this statement, don't you? How do the contents of the file "map" to your desired output?

                    Artur Grabowski wrote:

                    I will be grateful for help or advices

                    Put your keyboard away. What does "parsing the file" look like using paper and pencil?

                    "One man's wage rise is another man's price increase." - Harold Wilson

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    "You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles

                    A Offline
                    A Offline
                    Artur Grabowski
                    wrote on last edited by
                    #9

                    This is a script to do this in ruby :

                    #!env ruby

                    def parse(text)
                    text.split(',').map do |item|
                    key, value = item.split(':')
                    [key.to_i, value.to_f]
                    end.to_h
                    end

                    input_data = File.read(ARGV[0]).gsub("\r", "")

                    id = nil
                    entries = {}

                    input_data.split("\n").each do |line|
                    columns = line.split("|")

                    id = columns[0].to_i if columns.size == 3
                    entries[id] ||= {}

                    if columns.size == 3 || columns.size == 1
                    entries[id].merge! parse(columns.last)
                    elsif columns.size != 0
                    puts "? #{line}"
                    end
                    end

                    entries.sort_by { |k,v| k }.each do |key, weights|
                    puts
                    puts
                    puts "# neuron #{key}"

                    puts "source\tweight"
                    weights.sort_by { |k, v| k }.each do |source, weight|
                    puts "#{source}\t#{weight.to_s.gsub('.',',')}"
                    end
                    end

                    Thanks for help !!!

                    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