I have a program that writes on a text file. I'm using CStdioFile to write on a text file. The problem is, once the writing size exceeds 190kb, it stops from writing and causes the program to not to respond.

I tried threading in my application and the "not responding" issue was solved, but still, it can only write up to 190kb. Does anyone has an idea on what suppose to be the reason of this?

Recommended Answers

All 5 Replies

Post the (relevant) sourcecode? :)

THREADINFOSTRUCT *tis=(THREADINFOSTRUCT*)lParam;
	THREADPROCESSING_DIALOG code;
	int i = 0;

	CStdioFile source;
	source.Open(_T (fileName), CFile::modeReadWrite);
	CString temp = "";
	char str[500];
	int range = 0;
	while(source.ReadString(str, 500)) {
		PostMessage(tis->hWnd,WM_USER_THREAD_UPDATE_PROGRESS,i,fileSize);
		CString temp = "";
		CString translated = "";
		temp = temp + str;
		if ( temp.Find("(0.") >= 0 ) {
			int pair = 0;
repeat:		
			for ( int index = 0; index < temp.GetLength(); index++ ) {
				if ( temp.Mid(index, 1) == "(" ) {
					pair++;
				} else if ( temp.Mid(index, 1) == ")" ) {
					pair--;
				}
			}
			if ( pair != 0 ) {
				source.ReadString(str, 500);
				temp.TrimRight(" ");
				temp.TrimRight("\n");
				temp = temp + str;
				pair = 0;
				goto repeat;
			}
			translated = code.Convert(temp);
		} else {
			translated = temp;
		}
		ofstream destination ("C:/converted.txt", ios::app);
		destination << translated;
		destination.close();
		i++;
		temp.Empty();
		translated.Empty();
	}
	source.Close();
	PostMessage(tis->hWnd,WM_USER_THREAD_FINISHED,0,0);
	delete tis;
	return 0;

I suggest you get rid of the threads anyway: the problem is not that it's not multithreaded. Other than that I suggest sticking to either MFC functions or C++ functions. I'm not sure if "ifstream" works in MFC, but you could try since you also try to use "ofstream".

I tried to use ifstream but I encountered some problem using the "getline", so I just stick with the CStdioFile. I already encounter this problem when threading is still not implemented.
Waahhh.... What is the problem with this?

I suggest you use ifstream: more people know ifstream on this forum.

What problem did you have with getline()?

Be a part of the DaniWeb community

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