home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / os / msdos / programm / 11765 < prev    next >
Encoding:
Text File  |  1993-01-03  |  1.6 KB  |  58 lines

  1. Newsgroups: comp.os.msdos.programmer
  2. Path: sparky!uunet!mnemosyne.cs.du.edu!nyx!slindsay
  3. From: slindsay@nyx.cs.du.edu (Steve Lindsay)
  4. Subject: Erasing bytes from a file
  5. Message-ID: <1993Jan3.203234.5986@mnemosyne.cs.du.edu>
  6. Sender: usenet@mnemosyne.cs.du.edu (netnews admin account)
  7. Organization: Nyx, Public Access Unix @ U. of Denver Math/CS dept.
  8. Date: Sun, 3 Jan 93 20:32:34 GMT
  9. Lines: 47
  10.  
  11.  
  12. Hi all,
  13.     I have been trying to delete some characters
  14. from a text file with the below routine and it  only
  15. replaces the characters with spaces.  I would
  16. like those bytes gone completely not made
  17. into spaces.  Does anyone have a good idea?
  18. I am using DOS, VGA and Borland C++.
  19.  
  20. #include <iostream.h>
  21. #include <fstream.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24.  
  25. long filesize(FILE *stream);
  26. void main()
  27. {
  28.   FILE *stream;
  29.   int ctr;
  30.   char in_char;
  31.   int count=0;
  32.   int bytes;
  33.  
  34.   stream = fopen("DATA.002", "r+");
  35.   if (!stream)
  36.      {cout<<"\n*** Cannot open file ***\n";}
  37.  
  38.   while (in_char = getc(stream))
  39.     {if (in_char == '\n')
  40.        {count++;}
  41.      else
  42.        {bytes++;}
  43.     if (count==7)      //after 7 lines into the text file
  44.  {goto there;}
  45.     }
  46. there:for (ctr=0; ctr<5; ctr++)
  47.     {
  48.      fseek(stream,0L,SEEK_CUR);
  49.      fprintf (stream,"%c",'\x00');  //this is suppose
  50.                                                    to take away 5
  51.                                                    characters but it
  52.                                                    replaces the 5
  53.                                                    characters with 5
  54.                                                    spaces
  55.     }
  56. return; }
  57.  
  58.