TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JABO
from: KURT KUZBA
date: 1998-05-26 00:19:00
subject: H E L P

JM>   Problem: cant read and display Ansi file.
JM>   Attempt:
JM>   FILE* fptr;
JM>   main() {
JM>   char fileLine[80];
JM>   fptr=fopen("dude.ans", "r");
JM>   bla bla fgets(fileLine, 81, fptr);
JM>   bla bla fputs(fileLine);}
JM>   It shows tha ansi, just with a total black line inbetween
JM>   each line!  how do i fix this?
   Don't use puts()! Use printf().
   puts() automatically appends '\n' to the text, and in some
   cases, ( such as in DOS ), '\r' as well.
   You can also use a larger buffer and fread() and fwrite().
int display_ansi(char *src)
{
   FILE *source = fopen(src, "rb");
   char buf[512];
   int bytes_read = 1;
   if(source)
   {
      while(0 != (bytes_read = fread(buf, 1, 512, AnsiFile)))
         fwrite(buf, 1, bytes_read, stdout);
      fclose(source);
   }
   return !bytes_read;
}
   You should really be looking into a C++ solution, however.
   Once you have constructed an AnsiFile class, your entire
   code to read any .ANS file should look a little like this:
AnsiFile Dude("dude.ans");
if(Dude.display())
   cout << Dude.error() << flush;
   The C++ file copy routine I posted a short while ago using
   ifstream and ofstream could easily be changed to accomodate,
   since that is exactly what you want to do, is copy the date
   from an input stream to an output stream.
> ] It's a neat universe, but it certainly LOOKS chaotic........
---
---------------
* Origin: *YOPS ]I[* 8.4 GIG * RA/FD/FE * Milwaukee, WI (1:154/750)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.