Click here to Skip to main content
15,921,174 members
Home / Discussions / Managed C++/CLI
   

Managed C++/CLI

 
GeneralRe: Forum help Pin
Mark Salsbery30-Sep-07 7:12
Mark Salsbery30-Sep-07 7:12 
AnswerRe: Forum help Pin
George L. Jackson30-Sep-07 2:02
George L. Jackson30-Sep-07 2:02 
QuestionQuestions about reading binary files [modified] Pin
GentooGuy28-Sep-07 13:47
GentooGuy28-Sep-07 13:47 
AnswerRe: Questions about reading binary files Pin
Mark Salsbery28-Sep-07 15:16
Mark Salsbery28-Sep-07 15:16 
AnswerRe: Questions about reading binary files Pin
Mark Salsbery28-Sep-07 15:22
Mark Salsbery28-Sep-07 15:22 
GeneralRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 7:25
GentooGuy29-Sep-07 7:25 
GeneralRe: Questions about reading binary files Pin
Mark Salsbery29-Sep-07 7:39
Mark Salsbery29-Sep-07 7:39 
QuestionRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 8:05
GentooGuy29-Sep-07 8:05 
Okay thanks for the advice.
Currently, I'm having another small (I hope) problem:
#include "stdafx.h"<br />
#include <iostream><br />
#include <fstream><br />
 <br />
using namespace std;<br />
ifstream::pos_type size;<br />
char * memblock;<br />
<br />
void swapByteOrder();<br />
int readFile(char *filename);<br />
void printFile(int nr); // just for diag purposes only<br />
<br />
int main () <br />
{<br />
  if(!readFile("y:\\EXIF\\sanyo-vpcg250.jpg"))<br />
  {<br />
		cout <<"Some error occurred while opening the file"<< endl;<br />
		return 1;<br />
  }<br />
  printFile(10);<br />
  cout << endl;<br />
  swapByteOrder();<br />
  printFile(10);<br />
  return 0;<br />
}<br />
<br />
<br />
<br />
int readFile(char *filename)<br />
{<br />
  ifstream file (filename, ios::in|ios::binary);<br />
  if (file.is_open())<br />
  {<br />
	file.seekg(0, ios_base::end);<br />
	size = file.tellg();<br />
    memblock = new char [size];<br />
    file.seekg (0, ios::beg);<br />
    file.read (memblock, size);<br />
    file.close();<br />
<br />
    cout << "the complete file content is in memory\n";<br />
	<br />
	cout << "Size : "<< size  << endl;<br />
	for(int i=0;i<100;i++)<br />
	{	<br />
		char x = memblock[i];<br />
		cout << hex << (int)memblock[i]<<endl;<br />
	}	<br />
<br />
    delete[] memblock;<br />
  }<br />
  else cout << "Unable to open file";<br />
  return -1;<br />
}<br />
<br />
<br />
void swapByteOrder()<br />
{<br />
	long max = size;<br />
	char temp;<br />
	for(int i=0 ;i<max-2; i+=2)<br />
	{<br />
		temp=memblock[i];<br />
		memblock[i]=memblock[i+1];<br />
		memblock[i+1]=temp;<br />
	}<br />
}<br />
<br />
<br />
void printFile(int nr)<br />
{<br />
	for(int i=0;i<nr ;i++)<br />
	{<br />
		cout << hex << memblock[i] << endl;	<br />
	}<br />
<br />
}



The SwapByte function gets a access violation, when reaching i==3992. This is strange because it should be able to run to 62096 (the lenght of the file , as indicated by size).

What's going wrong here?
AnswerRe: Questions about reading binary files Pin
Mark Salsbery29-Sep-07 8:22
Mark Salsbery29-Sep-07 8:22 
GeneralRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 8:52
GentooGuy29-Sep-07 8:52 
GeneralRe: Questions about reading binary files Pin
Luc Pattyn29-Sep-07 9:15
sitebuilderLuc Pattyn29-Sep-07 9:15 
GeneralRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 9:20
GentooGuy29-Sep-07 9:20 
GeneralRe: Questions about reading binary files Pin
Mark Salsbery29-Sep-07 9:16
Mark Salsbery29-Sep-07 9:16 
GeneralRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 9:20
GentooGuy29-Sep-07 9:20 
GeneralRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 10:27
GentooGuy29-Sep-07 10:27 
GeneralRe: Questions about reading binary files Pin
GentooGuy29-Sep-07 10:52
GentooGuy29-Sep-07 10:52 
GeneralRe: Questions about reading binary files [modified*2] Pin
Mark Salsbery29-Sep-07 11:08
Mark Salsbery29-Sep-07 11:08 
GeneralRe: Questions about reading binary files [modified*2] Pin
GentooGuy30-Sep-07 2:40
GentooGuy30-Sep-07 2:40 
GeneralRe: Questions about reading binary files Pin
Mark Salsbery30-Sep-07 6:31
Mark Salsbery30-Sep-07 6:31 
GeneralRe: Questions about reading binary files Pin
GentooGuy30-Sep-07 6:37
GentooGuy30-Sep-07 6:37 
GeneralRe: Questions about reading binary files Pin
Mark Salsbery30-Sep-07 6:47
Mark Salsbery30-Sep-07 6:47 
GeneralRe: Questions about reading binary files Pin
GentooGuy30-Sep-07 6:55
GentooGuy30-Sep-07 6:55 
GeneralRe: Questions about reading binary files Pin
Mark Salsbery30-Sep-07 7:10
Mark Salsbery30-Sep-07 7:10 
GeneralRe: Questions about reading binary files Pin
GentooGuy30-Sep-07 14:51
GentooGuy30-Sep-07 14:51 
GeneralRe: Questions about reading binary files Pin
Mark Salsbery29-Sep-07 11:11
Mark Salsbery29-Sep-07 11:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.