Mail Archives: djgpp/1998/10/31/14:55:19
It's been about a week and I still haven't gotten any respoens, so I'll
try asking once more. I'm having a problem with code similar to the
following. The whole problem is when I set int number = 996546 it works
great, but when int number = 888888 it gives the wrong value.
I would very much appreciate any help.
--------------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----------------------------------
-Tim
- Raw text -