Hello, I happen to be a novice in the realm of C++, and I'm currently confused due to this error when trying to run my application:
"Assertion Failed. Expression 'stream != NULL' ".
I've looked it up, and nothing that comes up can answer why it gives me said error. I believe it has something to do with my code:

#include "stdafx.h"
#include <stdio.h>
#include <string>

using namespace std;
using namespace System;

int extractfiledata(const char oldf[], const char newf[])
	char idx[256];
	long size;
	FILE * tmpf, * updf;
	fopen_s(&tmpf, oldf, "w");
	fopen_s(&updf, newf, "r");
	size = ftell(updf);
	if(tmpf != NULL && updf != NULL)
		while(fread(idx, 1, size, updf))
			string tmpstr(idx);
			int pos=0;
			int chk=0;
				if(sizeof(updf) >= 256 && pos >= 256)
				if(chk == sizeof(updf))
				fwrite(&idx[pos], 1, sizeof(&idx[pos]), tmpf);
	return 0;

int main(array<System::String ^> ^args)
	char oldfile[] = "DoesThisWork.txt";
	char newfile[] = "DoesThisWork2.txt";
	extractfiledata(oldfile, newfile);
    return 0;

I'm basically trying to copy text from one file over to another file via strings. Any help is appreciated, thanks ahead of time.

Re: "Assertion Failed. Expression 'stream != NULL' " 80 80

read this article Seems to me it would be a whole lot easier to use managed streams. Don't ask me how because I have not done it. Something like this article.

Re: "Assertion Failed. Expression 'stream != NULL' " 80 80

> size = ftell(updf);
You do this BEFORE checking the file was opened successfully.

Besides, you just opened the file for reading, so the answer is trivially going to be zero.

> if(sizeof(updf)
This isn't going to tell you anything useful about the file.

> while(fread(idx, 1, size, updf))
Use fgets() to read a text file.

> fopen_s(&tmpf, oldf, "w");
I would generally advise avoiding non-portable vendor-specific functions.

Re: "Assertion Failed. Expression 'stream != NULL' " 80 80

Thanks for the help, got it to work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.