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. File Read/Write

File Read/Write

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 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.
  • C Offline
    C Offline
    chito
    wrote on last edited by
    #1

    Hello, I have a text file with the following layout. COMMAND1 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND2 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND3 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N .... COMMAND_N In this file, I have to insert new items, or change values of items or delete existing items. For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text. Is there any other alternative to do this. Can anybody tell what is the best method to do this. Thanks & regards, Chito

    A V 2 Replies Last reply
    0
    • C chito

      Hello, I have a text file with the following layout. COMMAND1 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND2 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND3 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N .... COMMAND_N In this file, I have to insert new items, or change values of items or delete existing items. For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text. Is there any other alternative to do this. Can anybody tell what is the best method to do this. Thanks & regards, Chito

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Well the assumption is rather correct but there is too many calls to the file. you should read the content of the file to the memory. Then do all the opertions (parsing, reallocation etc) and then the buffer (with the new value) should be written to the file again. The content fo your file looks like it can be easly stored by xml. And will be easier to parse. Have a good day

      1 Reply Last reply
      0
      • C chito

        Hello, I have a text file with the following layout. COMMAND1 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND2 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N COMMAND3 ITEM1 Value1 Value2 Value3 Valu4 ITEM2 Value1 Value2 Value3 Valu4 ITEM3 Value1 Value2 Value3 Valu4 ITEM4 Value1 Value2 Value3 Valu4 ... ITEM_N .... COMMAND_N In this file, I have to insert new items, or change values of items or delete existing items. For suppose if I want to insert new item under "COMMAND1", what I am doing is, seeking the pointer to the end of "COMMAND1", writing remainig text into a temporary file, inserting my new text, then appending the text which is stored in temporary file. But I guess, it is not a best method. It takes much time every time I insert/edit text. Is there any other alternative to do this. Can anybody tell what is the best method to do this. Thanks & regards, Chito

        V Offline
        V Offline
        valikac
        wrote on last edited by
        #3

        One solution is file-mapping. Kuphryn

        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