Mail Archives: djgpp/1998/10/26/13:25:19
On 26 Oct 1998, Martin Stromberg wrote:
> Tim (tssymanc AT ucalgary DOT ca) wrote:
> : I2luY2x1ZGUgPGZzdHJlYW0uaD4NDQojaW5jbHVkZSA8aW9zdHJlYW0uaD4N
> : DQoNDQppbnQgbWFpbigpew0NCg0NCiAgICAgICAgY2hhciB0ZXh0WzI2XTsN
>
> If you want feedback, post something readable.
>
> Right,
>
> MartinS
I don't know what happened, I can read both my post and attachment
perfectly... Anyhow I'll try this again. My problem is with the following
code, when I set number = 996546 the thing runs golden, but when number =
888888, the thing screws up, it reads back in the wrong number (It reads
back in something like -32000). I've tested the same code with CC and g++
and it worked fine with both. Anybody know why DJGPP is giving me the
grief? Did I do something wrong? Did I break some convention that I don't
know about?
--------------8<------------------------------------8<-------------------------------
#include <fstream.h>
#include <iostream.h>
int main(){
char text[26];
int number;
for(int x = 0; x < 25; x++)
text[x] = (x % 10) + '0';
text[25] = '\0';
number = 888888;
cout << "Before going through the file : " << endl;
cout << text << endl;
cout << number << endl;
fstream file;
file.open("data", ios::out);
file.write(text, sizeof(text));
file.write((char *) &number, sizeof(number));
file.close();
text[0] = 'N'; // TO SHOW IF THE STUFF IS ACTUALLY GETTING READ
text[1] = 'o'; //
text[2] = 'p'; //
text[3] = 'e'; //
text[4] = '!'; //
text[5] = '\0'; //
number = 0; //
file.open("data", ios::in);
file.read(text, sizeof(text));
file.read((char *) &number, sizeof(int));
file.close();
cout << "After going through the file : " << endl;
cout << text << endl;
cout << number << endl;
return(0);
}
-------->8---------------------------------------->8----------------------------------
Any help would be appreciated.
Thanks,
-Tim
- Raw text -