Click here to Skip to main content
16,005,467 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralCharts Pin
frankieb21-Mar-05 18:01
frankieb21-Mar-05 18:01 
GeneralRe: Charts Pin
Christian Graus21-Mar-05 18:26
protectorChristian Graus21-Mar-05 18:26 
GeneralRe: Charts Pin
Martijn van Kleef22-Mar-05 1:26
Martijn van Kleef22-Mar-05 1:26 
GeneralRe: Charts Pin
Anonymous23-Mar-05 15:25
Anonymous23-Mar-05 15:25 
GeneralRe: Charts Pin
Martijn van Kleef24-Mar-05 0:11
Martijn van Kleef24-Mar-05 0:11 
GeneralPocket PC 2003 c++ and iostream Pin
CLermen21-Mar-05 16:35
CLermen21-Mar-05 16:35 
GeneralRe: Pocket PC 2003 c++ and iostream Pin
Christian Graus21-Mar-05 18:27
protectorChristian Graus21-Mar-05 18:27 
GeneralDebug Assertion Failed! Pin
cockytrumpet21-Mar-05 14:32
susscockytrumpet21-Mar-05 14:32 
Hello,
I'm having a little problem. I don't get any compile or link errors
for this code, but when I run it I get:

Debug Assertion Failed!

Program: ...
File: fopen.c
Line: 53

Expression: file != NULL


<br />
#include <iostream><br />
#include <fstream><br />
<br />
using namespace std;<br />
<br />
unsigned char *openFile(char *, int&);<br />
<br />
int main(int argc, char **argv) {<br />
	unsigned char *buffer; // unsigned char = 8-bits<br />
	char *fileName;<br />
	int length;<br />
<br />
	if (argc != 1) {<br />
		cout << "Usage: " << argv[0] << " <pcap_file>" << endl;<br />
		exit(1);<br />
	} else {<br />
		fileName = argv[1];<br />
		buffer = openFile(fileName, length);<br />
	}<br />
<br />
	return 0;<br />
}<br />
<br />
unsigned char *openFile(char *fileName, int &length) {<br />
	char *temp_buffer;<br />
	unsigned char *buffer;<br />
	ifstream theFile;<br />
<br />
	theFile.open(fileName, ios::in|ios::binary);<br />
	if (!theFile) {<br />
		cout << "Can't open file " << *fileName << "!" << endl;<br />
		exit(1);<br />
	}<br />
<br />
	// get length of file<br />
	theFile.seekg(0, ios::end);<br />
	length = theFile.tellg();<br />
	theFile.seekg(0, ios::beg);<br />
<br />
	// allocate memory<br />
	temp_buffer = new char [length];<br />
	buffer = new unsigned char [length];<br />
<br />
	// read data<br />
	theFile.read(temp_buffer,length);<br />
	theFile.close();<br />
<br />
	buffer = (unsigned char *) temp_buffer;<br />
	<br />
//	delete[] temp_buffer; // why not!?<br />
	// What's an assertion failure?<br />
	// That doesn't sound good. ;)<br />
	return buffer;<br />
}<br />


The last delete[] temp_buffer; causes an assertion failure too,
when uncommented. I assume I'm makeing a really simple mistake. Anyone see it?
GeneralRe: Debug Assertion Failed! Pin
Christian Graus21-Mar-05 14:58
protectorChristian Graus21-Mar-05 14:58 
GeneralRe: Debug Assertion Failed! Pin
David Crow22-Mar-05 2:57
David Crow22-Mar-05 2:57 
GeneralSystem process Pin
giany00721-Mar-05 11:48
giany00721-Mar-05 11:48 
GeneralRe: System process Pin
Tom Wright21-Mar-05 12:21
Tom Wright21-Mar-05 12:21 
GeneralRe: System process Pin
giany00721-Mar-05 23:10
giany00721-Mar-05 23:10 
GeneralRe: System process Pin
Blake Miller22-Mar-05 5:58
Blake Miller22-Mar-05 5:58 
Generalmfc dll and IWebBrowser2 questions Pin
Spiritofamerica21-Mar-05 10:51
Spiritofamerica21-Mar-05 10:51 
GeneralRe: mfc dll and IWebBrowser2 questions Pin
David Crow21-Mar-05 11:01
David Crow21-Mar-05 11:01 
GeneralRe: mfc dll and IWebBrowser2 questions Pin
Anonymous22-Mar-05 4:55
Anonymous22-Mar-05 4:55 
GeneralWriting Variables in CDialog with MFC Pin
NewbieStats21-Mar-05 9:45
NewbieStats21-Mar-05 9:45 
GeneralRe: Writing Variables in CDialog with MFC Pin
Ravi Bhavnani21-Mar-05 10:01
professionalRavi Bhavnani21-Mar-05 10:01 
GeneralRe: Writing Variables in CDialog with MFC Pin
NewbieStats21-Mar-05 10:19
NewbieStats21-Mar-05 10:19 
GeneralRe: Writing Variables in CDialog with MFC Pin
Ravi Bhavnani21-Mar-05 10:37
professionalRavi Bhavnani21-Mar-05 10:37 
GeneralRe: Writing Variables in CDialog with MFC Pin
NewbieStats21-Mar-05 10:51
NewbieStats21-Mar-05 10:51 
GeneralRe: Writing Variables in CDialog with MFC Pin
David Crow21-Mar-05 10:57
David Crow21-Mar-05 10:57 
GeneralRe: Writing Variables in CDialog with MFC Pin
Ravi Bhavnani21-Mar-05 11:11
professionalRavi Bhavnani21-Mar-05 11:11 
GeneralRe: Writing Variables in CDialog with MFC Pin
NewbieStats21-Mar-05 11:28
NewbieStats21-Mar-05 11:28 

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.