delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/14/22:00:48

Message-ID: <364E3F13.8CEE8402@videotron.ca>
From: Dac Chartrand <conner AT videotron DOT ca>
X-Mailer: Mozilla 4.5 [en] (Win95; I)
X-Accept-Language: fr,en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Better way of modyfing file contents in C++ [DJGPP]?
Lines: 73
Date: Sat, 14 Nov 1998 21:40:19 -0500
NNTP-Posting-Host: 207.253.0.181
X-Complaints-To: abuse AT videotron DOT net
X-Trace: weber.videotron.net 911097376 207.253.0.181 (Sat, 14 Nov 1998 21:36:16 EDT)
NNTP-Posting-Date: Sat, 14 Nov 1998 21:36:16 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Please respond to sender and newsgroup, Thanks.

Hi, I'm using DJGPP and I was wondering if there was a more efficient
way to append information and delete information from a simple txt file
then my following method:

/* cheap method of adding user to access.dat by using a temp file
instead of ofstream library which didn't seem to work for me. */

          while(1) {
          ifstream fin("access.dat");
          ofstream fout("temp.dat");
          while (fin >> UserNameFileValue >> UserPasswordFileValue) {
                fout << UserNameFileValue << " " <<UserPasswordFileValue
<< endl;
          }
          fout << GivenUserName << " " << GivenPassword << endl;
          fout.close();
          fin.close();
          rename("temp.dat", "access.dat");
          return 0;
          }

[snip]

/* cheap method of deleting a user  */

if (prompt == 1) {

ifstream fin("access.dat");
ofstream fout("temp2.dat");

while (fin >> UserNameFileValue >> UserPasswordFileValue) {
      if (GivenUserName != UserNameFileValue) {
      fout << UserNameFileValue << " " <<UserPasswordFileValue << endl;
      }
      else if (GivenUserName == UserNameFileValue) {
      continue;
      }
}

/* for some reason, does not rename the file like it did earlier?
can't figure out why. The temp.dat is properly modified, but it won't
rename the file, which is where I got stuck. */

fout.close();
fin.close();
rename("temp2.dat", "access.dat");
cout << "User deleted, logging off..." << endl;
return 0;

}

[snip]

/* The access.dat file looks like this: Left Side is username, right
side is password */

oword1 xtRstE
owurd2 123abC8
owerd3 X1_eue3_
owyrd4 12345z
dachart blahblah
chartda dachart

[snip]

This is as short of a code I felt I could include. Please excuse me if
it is overwhelming to regular bandwidth use. Thank you for your time.

-- 
Alone Counter Productions / Intellectual Militia Recordings
Hammer have you seen her? http://pages.infinit.net/acp/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019