read part of text in file

This is a discussion on read part of text in file within the C++ Programming forums, part of the General Programming Boards category; my program logic : user open the program daily, enter the amount spent, program will create / read and record ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Location
    Cyberjaya, Malaysia
    Posts
    1

    read part of text in file

    my program logic : user open the program daily, enter the amount spent, program will create / read and record the number, user closed the program, continue next day..

    The challenge :
    I set the total saving of user to a fixed amount. However if the program once closed, the program can't work, it will just deduct from the fixed amount, so i plan to read the latest saving (or you guys have better way?)

    Let say I have this in a file




    Code:
    Date        Amount spend    Saving left
    
    
    11/23/11        -20.00USD    980.00USD

    How to read just only the "RM 980.00"? read the last few char of the file? or use seek? I'm a newbie..

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,500
    You read the whole file, and you extract what you need.

    If you want to 'edit' the file in some way, you read the whole file, make your changes in memory and then write the whole file (ideally to a new file, and then rename the old one to be a backup).

    Text files do not support random access updates if the length of the file is going to change as a result.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. read part of png file
    By fleurdelys in forum Game Programming
    Replies: 8
    Last Post: 10-23-2011, 04:19 AM
  2. Reading Multiple Multi-Part Strings From a Text File
    By bengreenwood in forum C++ Programming
    Replies: 2
    Last Post: 06-02-2009, 10:43 AM
  3. Read part of file
    By Martin Kovac in forum C Programming
    Replies: 1
    Last Post: 04-13-2009, 01:51 PM
  4. Reading Part Of A Text File
    By Okiesmokie in forum C++ Programming
    Replies: 1
    Last Post: 03-01-2002, 12:59 PM
  5. How do i delete a certain part of a text file?
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 09-08-2001, 06:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21