home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.msdos.programmer
- Path: sparky!uunet!mnemosyne.cs.du.edu!nyx!slindsay
- From: slindsay@nyx.cs.du.edu (Steve Lindsay)
- Subject: Erasing bytes from a file
- Message-ID: <1993Jan3.203234.5986@mnemosyne.cs.du.edu>
- Sender: usenet@mnemosyne.cs.du.edu (netnews admin account)
- Organization: Nyx, Public Access Unix @ U. of Denver Math/CS dept.
- Date: Sun, 3 Jan 93 20:32:34 GMT
- Lines: 47
-
-
- Hi all,
- I have been trying to delete some characters
- from a text file with the below routine and it only
- replaces the characters with spaces. I would
- like those bytes gone completely not made
- into spaces. Does anyone have a good idea?
- I am using DOS, VGA and Borland C++.
-
- #include <iostream.h>
- #include <fstream.h>
- #include <stdlib.h>
- #include <stdio.h>
-
- long filesize(FILE *stream);
- void main()
- {
- FILE *stream;
- int ctr;
- char in_char;
- int count=0;
- int bytes;
-
- stream = fopen("DATA.002", "r+");
- if (!stream)
- {cout<<"\n*** Cannot open file ***\n";}
-
- while (in_char = getc(stream))
- {if (in_char == '\n')
- {count++;}
- else
- {bytes++;}
- if (count==7) //after 7 lines into the text file
- {goto there;}
- }
- there:for (ctr=0; ctr<5; ctr++)
- {
- fseek(stream,0L,SEEK_CUR);
- fprintf (stream,"%c",'\x00'); //this is suppose
- to take away 5
- characters but it
- replaces the 5
- characters with 5
- spaces
- }
- return; }
-
-