www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/09/24/14:17:40

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: read a file backwards
Date: 24 Sep 2001 18:04:46 GMT
Organization: Cornell University
Lines: 46
Sender: asu1 AT cornell DOT invalid (on 128.253.251.163)
Message-ID: <Xns91268F12EAB66ASINANUNUR@132.236.56.8>
References: <3BAF4C56 DOT 3F2904BC AT erols DOT com>
NNTP-Posting-Host: 128.253.251.163
X-Trace: news01.cit.cornell.edu 1001354686 27237 128.253.251.163 (24 Sep 2001 18:04:46 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 24 Sep 2001 18:04:46 GMT
User-Agent: Xnews/4.06.22
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Chris Smith <herrsmitty AT erols DOT com> wrote in 
news:3BAF4C56 DOT 3F2904BC AT erols DOT com:

> Hello everyone,
> I am working on a small encryption utility program. At one point in the
> program I need to be able to read a file backwards. Have I missed
> something specific about djgpp, or have I just over looked the obvious?
> Below is a sample of the code I am attempting to use:
> 

try the following:


#include <fstream>

int main(int argc, char *argv[])
{
	char c;
	int i;
	int myeof;
	
	ifstream fin(argv[1], ios::binary);

	if( fin == NULL )
		exit(1);

	fin.seekg(0, ios::end);

	myeof = - ( fin.tellg() + 1);

	for( int i = -1; i > myeof; --i)
	{
		fin.seekg(i, ios::end);
		fin.get(c);
		cout << c;
	}

	fin.close();

	return 0;
}

-- 
--------------------------------
A. Sinan Unur
http://www.unur.com/

- Raw text -


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