Thread: files

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    16

    files

    i am opening a text file using r+ the purpose is to read a float value into the program, do the calculation then write the modified value back into the file ready to be read again the next time it is needed, but when the program is writing the modified value back it is just writing it on the end of the original value instead replacing it. any ideas on how i can get the program to replace the original float value so that the file only ever consists of one float value. it may seem simple to someone out there but help i am a neewbie.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Use fseek() to move the file position pointer back to where the float is stored

    fread( &myfloat, sizeof(float), 1, fp );
    fseek( fp, -sizeof(float), SEEK_CUR );
    fwrite( &myfloat, sizeof(float), 1, fp );

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ressources files
    By mikahell in forum Windows Programming
    Replies: 4
    Last Post: 06-19-2006, 06:50 AM
  2. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  3. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  4. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  5. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM