Skip to main content
GameDev.net gamedev.net
🔒 Locked

File stream troubles...

Started by elis-cool Oct 16, 2002 at 4:13 AM 26 replies 600+ views
Original Post
elis-cool
elis-cool
Ok, it seems to stop writing to the file haveway through my function... heres the code, ive written all the main stuff in the middle but cant debug it since I have no output... so dont complain if im doing something wrong thats not file related
  
//--------------------------

// Function: BuildOutputCpp()

// Inputs: filename - file to save to

// Outputs: None

//

// Description: Parses this->pszOutput and saves resultent HTML file

//--------------------------

void BuildOutputCpp(char* filename, char* pszOutput, int iSize, char* pszTitle)
{
	ofstream File(filename, ios::binary);
	if(!File)
	{
		File.close();
		MessageBox(CApp.GetMainWnd(), "BuildProjectFile() failed", "Error", MB_ICONERROR | MB_OK);
		return;
	}

	char szWord[200];
	bool bEnterWord = false;
	bool bCopy = false;
	char* pszCode = 0;
	int iLen;

	// Headers

	File.write((char*)"<html>\r\n<head>\r\n  <title>", strlen("<html>\r\n<head>\r\n  <title>"));
	File.write((char*)pszTitle, strlen(pszTitle));
	File.write((char*)"</title>\r\n</head>\r\n\r\n", strlen("</title>\r\n</head>\r\n\r\n"));
	File.write((char*)"<body bgcolor=\"#FFFFFF\" text=\"#000000\">\r\n", strlen("<body bgcolor=\"#FFFFFF\" text=\"#000000\">\r\n"));
	File.write((char*)"<font size=\"3\"><br>\r\n", strlen("<font size=\"3\"><br>\r\n"));

	// Preceeding code

	if(SendMessage(GetDlgItem(CApp.GetMainWnd(), IDC_CHECKADDPRECEEDING), BM_GETCHECK, 0, 0) == BST_CHECKED)
	{
		iLen = GetWindowTextLength(GetDlgItem(CApp.GetMainWnd(), IDC_EDIT3));
		if(iLen != 0)
		{
			pszCode = new char[iLen+1];
			GetWindowText(GetDlgItem(CApp.GetMainWnd(), IDC_EDIT3), pszCode, iLen+1);
		
			File.write((char*)pszCode, strlen(pszCode));
			File.write((char*)"\r\n\r\n", strlen("\r\n\r\n"));
			delete[] pszCode;
		}
	}
/////////// NOTHING WRITTEN TO FILE AFTER HERE ///////////

	for(int i = 0; i < iSize; i++)
	{
		// Check to see if its the beggining of a word

		for(int k = 66; k < 90; k++) // a - z

		{
			if(pszOutput[i] == k)
			{
				bEnterWord = true;
				break;
			}
		}

		if(!bEnterWord)
		{
			for(int e = 97; e < 122; e++) // A - Z

			{
				if(pszOutput[i] == e)
				{
					bEnterWord = true;
					break;
				}
			}
		}

		// Ok a word has started

		if(bEnterWord)
		{
			szWord[0] = pszOutput[i++];

			// Get the word

			for(int u = 0;; u++, i++)
			{
				bCopy = false;

				// Check if its a valid character

				for(int r = 66; r < 90; r++) // a - z

				{
					if(pszOutput[i] == r){bCopy = true; break;}
				}

				if(!bCopy)
				{
					for(int k = 97; k < 122; k++) // A - Z

					{
						if(pszOutput[i] == k){bCopy = true; break;}
					}
				}

				// if its a vaild char then copy it else its the end of the word

				if(bCopy) szWord[u] = pszOutput[i];
				else
				{
					szWord[++u] = ''\0''; // Attach NULL

					break;
				}
			}

			// The word is now stored in szWord

			// Check it to see if we need to color code it

			if(IsReservedCpp(szWord))
			{
				File.write((char*)"<font color=\"#0000FF\">", strlen("<font color=\"#0000FF\">")); 
				File.write((char*)szWord, strlen(szWord));
				File.write((char*)"</font>", strlen("</font>")); 
			}
			else File.write((char*)szWord, strlen(szWord));
		}
		else File.write((char*)pszOutput[i], 1);

		bEnterWord = false;
	}

	// Appendage code

	if(SendMessage(GetDlgItem(CApp.GetMainWnd(), IDC_CHECKADDAPPENDAGE), BM_GETCHECK, 0, 0) == BST_CHECKED)
	{
		iLen = GetWindowTextLength(GetDlgItem(CApp.GetMainWnd(), IDC_EDIT4));
		if(iLen != 0)
		{
			pszCode = new char[iLen+1];
			GetWindowText(GetDlgItem(CApp.GetMainWnd(), IDC_EDIT4), pszCode, iLen+1);

			File.write((char*)pszCode, strlen(pszCode));	
			File.write((char*)"\r\n\r\n", strlen("\r\n\r\n"));
			delete[] pszCode;
		}
	}

	File.write((char*)"</font>\r\n</body>\r\n</html>", strlen("</font>\r\n</body>\r\n</html>"));

	File.close();
}  
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
nes8bit
nes8bit
Damn''t elis. Your code doesn''t even COMPILE.

on line one I get


Compile error:

Expected: line number or label or statement or end of statement


---------------------------------------------
"Love is a disease"
nes8bit
nes8bit
Also, all the code turns red for some reason. You need to learn how to program.

---------------------------------------------
"Love is a disease"
elis-cool
elis-cool
quote:
Original post by nes8bit
Damn't elis. Your code doesn't even COMPILE.
on line one I get

Compile error:
Expected: line number or label or statement or end of statement


---------------------------------------------
"Love is a disease"

Shut up you VB whore!

EDIT:
quote:

Also, all the code turns red for some reason. You need to learn how to program.

At least I can program decently in something decent



[edited by - elis-cool on October 16, 2002 5:27:01 AM]
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
nes8bit
nes8bit
No way, C++ sux. VB is better. C++ requires runtime. Most notably MFC. VB does not because it is better. I use VB to hack on my AOL so shut up. I''d like to see you hack on AOL. Do you hack elis? I don''t think so. Maybe that''s what you''re trying to use your 3d file stream for, hacking.

---------------------------------------------
"Love is a disease"
nes8bit
nes8bit
By the way, your code was VB, idiot. That''s why it wouldn''t compile.

---------------------------------------------
"Love is a disease"
elis-cool
elis-cool
quote:
Original post by nes8bit
No way, C++ sux. VB is better. C++ requires runtime. Most notably MFC. VB does not because it is better. I use VB to hack on my AOL so shut up. I''d like to see you hack on AOL. Do you hack elis? I don''t think so. Maybe that''s what you''re trying to use your 3d file stream for, hacking.

---------------------------------------------
"Love is a disease"

LOL! dude... yes we all know that the C++ requiring MFC for runtimes is very bad, and plans are underway as we speak to abolish this evil microsoft doing, as we all know they control the language. And yes ive been secretly using my 3d file stream for hacking, and ive been hacking into AOL so no one else can hack! AND THEN I WILL BE THE ONLY 1337 h4x0r!1
PS. now could I plz have some serious responses to this thread

[email=esheppard@gmail.com]esheppard@gmail.com[/email]
nes8bit
nes8bit
Do you think I''m joking? I researched this information on google. It''s totally underground, but totally legit. Trust me. Here are some links ...

http://www.google.com/
http://www.yahoo.com/

---------------------------------------------
"Love is a disease"
elis-cool
elis-cool
nes...
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
nes8bit
nes8bit


---------------------------------------------
"Love is a disease"
elis-cool
elis-cool
[email=esheppard@gmail.com]esheppard@gmail.com[/email]
nes8bit
nes8bit
woooooooooooo0000000000000000000000t!!!!!!!!!!

I am the POSTER QUE....KING!!!! KING I SAY!!!!!!

---------------------------------------------
"Love is a disease"
nes8bit
nes8bit
Anyway, back to the discussion about VB and C++. I think VB is much better than C++ because it''s easier to use. Elis is on crack, don''t listen to him. His opinion is wrong and my opinion has factual backing.

See, I like VB, that is a fact. I do not like C++. That is also a fact. His opinion is wrong. Thank you. I need sleep.

---------------------------------------------
"Love is a disease"
pan narrans
pan narrans
quote:
Original post by nes8bit
Anyway, back to the discussion about VB and C++. I think VB is much better than C++ because it''s easier to use. Elis is on crack, don''t listen to him. His opinion is wrong and my opinion has factual backing.

See, I like VB, that is a fact. I do not like C++. That is also a fact. His opinion is wrong. Thank you. I need sleep.

---------------------------------------------
"Love is a disease"


I would like to disagree. But I am scared, so I won''t.


pan narrans
Study + Hard Work + Loud Profanity = Good Code
Minister of Propaganda : leighstringer.com : Nobody likes the man who brings bad news - Sophocles (496 BC - 406 BC), Antigone
nes8bit
nes8bit
Good, you''ll lose the fight anyway...

So what''s with the {}''s in C++? They''re SO USELESS. I hate them, it ruins all the structure in the code.

---------------------------------------------
"Love is a disease"
elis-cool
elis-cool
quote:
Original post by Erunama
You created your own function to make HTML files out of source files? You should download Dev-C++. The latest beta has an option to output files (or even the whole project, nicely organized) to HTML files. It is also quite stable.

|.dev-c++.|.the gimp.|.seti@home.|.dbpoweramp.|.torn.|.=w=.|

oh well, I felt like making my own... its good fun/practice/learning and it can\will do multiple languages... and it has the interface the way I like it

[email=esheppard@gmail.com]esheppard@gmail.com[/email]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.