473,484 Members | 1,667 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problem with fstream::read

21 New Member
I'm having a problem with read , my code is somewhat like:
Expand|Select|Wrap|Line Numbers
  1. char chipMemory [chipMemorySize]; // ~35XX
  2. fstream ifile;
  3. ifile.open(argv[1],ios::in|ios::binary|ios::nocreate|ios::ate);
  4. int fileLength=ifile.tellg();
  5. ifile.seekg(ios::beg);
  6. ifile.read(chipMemory,fileLength);
  7. ifile.close();
After the last function call in the program, (Note , this is an extract , and seemingly irrelevant pieces have been removed)
(short) chipMemory[0] "prints as" (printf used) 0xFFFFFFE0
(short chipMemory[2] "prints as" 0xFFFFFFEE
it should contain:
(short) chipMemory[0] == 0x00E0;
(short) chipMemory[2] == 0x00EE;
What I'm most puzzled about is that a short is 2 bytes , so the maximum short would be 0xFFFF , not even close to 0xFFFFFFE0.
I'm guessing this is because the file starts with a nul (0x00) , which is supposed
to mark the end of a file.
(Note : I'm not checking for nul in any way at all)
Jul 19 '08 #1
1 1826
jabbah
63 New Member
Im not prefectly sure but could it be that 0x00E0 overflows char? should you be using unsigned char?


Expand|Select|Wrap|Line Numbers
  1. printf("%d\n", 0x00E0 );
  2. char c = 0x00E0;
  3. printf("%d\n", c);
  4. printf("0x%x\n", c);
  5. printf("0x%x\n", (short)c);
  6.  
Jul 22 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

20
2633
by: titi | last post by:
Question The road and traffic authority for a small country currently uses a system to store information about all 'currently' licensed drivers. A licensed driver has the following info stored...
2
6074
by: dumboo | last post by:
hi there i m using fstream object for reading through and writing to my file, using following code char c; while(!m_aa.eof()) { m_aa.read(&c, sizeof(c)); m_oo.write(&c, sizeof(c));
1
1629
by: Patrick | last post by:
Hi I try to parse an XML Document with the following commands: response = http.responseXML.documentElement; up_since =response.getElementsByTagName('up_since').firstChild.data; So I try to...
5
1949
by: Scott Shuster | last post by:
Hi, I'm having some strange problems in VS employing a DataReader. Here's a small snippet of the code: .... objDR = objCMD.ExecuteReader() If objDR.Read() Then (true stuff) Else
5
1368
by: Simon Verona | last post by:
I have a pair of functions that I'm calling using remoting - called readfile and writefile. The readfile works fine when called from the client PC. The writefile method returns an error: ...
5
2022
by: znubbe | last post by:
Hi, I hope anyone can help me with this problem. I have a field of image type in a SQL 2000 database. I'm using this code to insert a document: Dim conn Dim rs Dim oStream
10
3576
by: Hunk | last post by:
Hi I would like some ideas on way to solve the concurrency issue. The problem is , I have an object say X which multiple readers need to access and also to update. They do so by say two...
7
1929
by: nma | last post by:
Hi I'm trying to display data in a table list format but error message like this appear. What is wrong with the code? "Parse error: syntax error, unexpected '<' in C:\htdocs\...\MB2movieinfo.php...
8
33077
by: No Signal X | last post by:
hello i'm having a problem in reading a text file line by line with splitting words, counting the number of lines & words and saving the position of each word i've started with this : public...
0
7080
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7140
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6811
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5403
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4841
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3044
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1355
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
588
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.