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)
|