1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

noob programmer needs a hand with file IO =(

Discussion in 'C' started by tichonga, Dec 4, 2007.

  1. tichonga

    tichonga New Member

    Been working on this for a whole day now. I need to write text at a particular point in a file.

    CODE:
    Code:
    /* fseek example */
    #include <stdio.h>
    
    int main ()
    {
    FILE * pFile;
    pFile = fopen ( "myfile.txt" , "w" );
    fputs ( "This is an apple." , pFile );
    fseek ( pFile , 9 , SEEK_SET );
    fputs ( " sam" , pFile );
    fclose ( pFile );
    return 0;
    }
    OUTPUT:

    This is an apple. sam

    SHOULD BE:

    This is a sample.


    Could it be my compiler? I just have a crappy one that I downloaded online somewhere.


    fflush(pFile)

    after my first fputs() doesn't work either. =(
     
    Last edited by a moderator: Dec 4, 2007
  2. tichonga

    tichonga New Member

    fixt. was my compiler
     
  3. shabbir

    shabbir Administrator Staff Member

    If you are opening the file using "w" that means its created newly and so it does not have a position you are specifying because fseek cannot put a pointer beyond EOF.
     
    Last edited: Dec 4, 2007

Share This Page