From: Tim Newsgroups: comp.os.msdos.djgpp Subject: Need help with binary file I/O Date: Sat, 31 Oct 1998 12:15:14 -0700 Organization: The University of Calgary Lines: 60 Message-ID: <71fnk7$4oe@ds2.acs.ucalgary.ca> References: <70thdn$kfe AT ds2 DOT acs DOT ucalgary DOT ca> <711qg3$hbq$2 AT antares DOT lu DOT erisoft DOT se> <712e6q$c1i AT ds2 DOT acs DOT ucalgary DOT ca> NNTP-Posting-Host: tssymanc AT acs2 DOT acs DOT ucalgary DOT ca Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Sender: tssymanc AT acs2 DOT acs DOT ucalgary DOT ca In-Reply-To: <712e6q$c1i@ds2.acs.ucalgary.ca> To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com 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 #include 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