Thread: Writing to a file at a certain position.

  1. #1
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428

    Writing to a file at a certain position.

    Hey all, I checked the faq, and did a search, but I couldnt find any info on writing to a file at a certain position (why does the search not allow words less then 4 characters long?). What I need is to be able to write to a file at the second to last line (before some certain text) in the file, so I can't just append it to the end. Thanks.

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,212
    *count the lines in the file using a fgets loop
    *fseek to the start
    *do fgets for total lines-2
    *there's your line

  3. #3
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Thanks, was talking to soemone on AIM, and got it working, but something really strange is happening now, so if we cant figure it out tehn maybe ill post some source for everyone to look at. thanks

  4. #4
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    ok, i uploaded the soruce, http://www.labino.net/tutorials/cmwierd.zip the problem is around line 270, where instead of just printing 'BLURG' to the end of the file, it prints <question>this is a test <anBLURG

    <an is short for <answer>, as it backs up 5 spaces before it prints BLURG. I have no idea why it prints the '<question>this is a test <an' part, as it is not mentioned anywhere in the code. Anyone have any ideas? Thanks

  5. #5
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Maybe fout.ignore(10);

  6. #6
    Registered User dirkduck's Avatar
    Join Date
    Aug 2001
    Posts
    428
    Thanks, but still no luck. Any more ideas?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  2. Button handler
    By Nephiroth in forum Windows Programming
    Replies: 8
    Last Post: 03-12-2006, 06:23 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  5. Writing input from a file into shared memory
    By RazielX in forum C Programming
    Replies: 2
    Last Post: 09-23-2004, 12:34 PM