Thread: rewrite to file

  1. #1
    Registered User
    Join Date
    Dec 2006

    rewrite to file

    i want that my prog will rewrite (update) to exsist file if it was found a string im searching for inside this file, so i did this:
    fptr=fopen("data.txt","r+"); // i also tried "a+"
    fscanf(fptr,"%s\n",tmp_name); //tmp_name is a vector.
    if (strcmp(myname,tmp_name)==0)
    fprintf("%d %d %f %d",won,lost,avg,best);
    my file is a txt file and looks like this:

    1 2 3.3 5
    1 2 3.3 5

    and i want to chk if name1==myname then change the 1 2 3.3 5 to 7 8 9.9 5
    did what i was doing is illigel ? coz i cant get it to work...(the fprintf is doing nothing..), or maybe some1 know other way to do this ?
    thanks !

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Don't spam the board with the same question in different forums.
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  2. Making a LIB file from a DEF file for a DLL
    By JMPACS in forum C++ Programming
    Replies: 0
    Last Post: 08-02-2003, 08:19 PM
  3. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  4. me take a look at this: File Encryptor
    By heljy in forum C Programming
    Replies: 3
    Last Post: 03-23-2002, 10:57 AM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM