Ok, so i don't think I need to post all the code....most of you have seen a lot of it anyways, if I need to I don't mind. But anyways, I made the outFileDrs Stream, then at the end of the program it closes it. But its only 1 kb? It should be around 50,000 kbs......

Any fast ideas on what may not be working?

EDIT: Maybe this piece of code....?

char *tempData = new char [1];
	delete [] tempData;
    for each (auto outTable in outTables)
    {
		for each (auto outItem in outTable.Items)
		{
			tempData = new char [outItem.Data.size()];
			for each (char byt in outItem.Data)
			{
				*tempData += byt;
			}
			outFileDrs.write(tempData, outItem.Data.size());
			delete [] tempData;
		}
    }

Recommended Answers

All 9 Replies

edited above

I don't know about that problem about the size of the file. I would suggest you step through the code and/or print out the sizes of all there arrays (size of outTables, outTable.Items, and outItem.Data) to see if the problem is with the file stream or with the construction of those arrays.

Line 10 seems very very wrong to me. From looking at this code, it is clear that whatever is saved in outFileDrs, it is complete garbage (completely arbitrary data). I don't know what you think line 10 is supposed to do, but I can tell you it is not what you think it does. What it does is add up all the values in outItem.Data and store them in the first element of tempData, starting from a garbage value. And all the other elements (from the 2nd to the last) in tempData remain set at garbage values. There is no way that this is what you want. You should clarify what that loop is supposed to do.

This was the original C# piece of code. the SelectMany() function takes all the outTable.Items and pretty much combines them all into one MASSIVE table

foreach (var outItem in outTables.SelectMany(outTable => outTable.Items))
            {
                var ndp = newDrs.Position;
                Trace.Assert(ndp == outItem.Start);
                writer.Write(outItem.Data);
            }

It said the sizeof(outTables) was 20................wtf?

I have to say. The more I read your posts, the more I get the idea that you may not even have written a single line of code in C++ before starting this project of translating a C# library into C++. One thing that is true in natural languages (English, French, etc.) is that no-one is qualified, regardless of how much schooling they have, to translate into a language that is not their native language (this is by law in Canada: you cannot be officially accredited to translate from language A to language B, if language B is not your native language). From what I have seen, in programming, pretty much the same logic applies (except that "native" languages are the few languages in which one is entirely proficient). A programmer mainly proficient in C++ can translate almost any code into C++ code, but never the other way around, because the quality will be horrible if you try to translate into a language you are not totally proficient in. You should maybe consider that you may not be qualified to translate code into C++, because from what I have seen, you seem to go about it quite blindly. If you are doing this for someone, maybe that someone would be better served by an experienced C++ programmer. If you really need to do this yourself, man.. this will be a brutal crash course in C++. Get a good book on C++, it might help.

BTW:
>>It said the sizeof(outTables) was 20................wtf?
When you use the sizeof operator, it gives you the size of the type of the variable "outTables" not the number of elements in the array. Depending on what outTables is, there should be a function like outTables.size() that will give you the number of elements in this array. (This is why I remarked that you seem to have no experience in C++, because the sizeof() operator is one of the most basic things in C++, and anybody who has done a basic course or read a basic book on C++ would not have to ask why sizeof(outTables) returns 20 and not the number of elements in the array.)

I read a 1000 page C++ book and programmed all of the examples in the book before I got this project. So no, i am not clueless. I know how to write in the C++ Language basic programs, but there is no doubt this one is partially beyond me. I have learned a lot from reading all the posts of the community with this project and all of the code that has been given to me as well. The book did not prepare me for anything of such magnitude as this project. It also did not prepare me to convert from C# to C++ which imo is a horrible idea, but never the less its what I am supposed to be doing. I got the exe Patcher part which is the first 1000 lines of code pretty easily, had a few problems along the way which I got help with, but this part of the patcher is getting me confused as hell. The book did not prepare me for such an elaborate use of the I/O system. Nor did it go over stringstreams which I now understand thanks to you. It did not show me how to use the reinterpret_cast<char*> which I also needed thanks to you. So what I am trying to say here is, yes I have done a lot of BASIC C++, just like any newbie, but I am also learning a lot from this project.

So ty for all the help you have given me so far. I truly do appreciate it.

I am going to take another shot at this writing of the file, i just found out that its only writing through one of the arrays, which would be explaining why its so small. If you could help with the small piece of code i provided above in C# i would appreciate it. I hate these LINQ expressions, they are confusing to translate, but I do know what it is supposed to do....Ty :)

What you find below seems to do what you want.

for (int q = 0; q < tableCount; ++q)
{
  for (int j = 0; j < outTables[q].Items.size(); ++j)
  {
    outFileDrs.write(&(outTables[q].Items[j].Data[0]), outTables[q].Items[j].Data.size());
  }
}

Perfect :D Ok, ty for all of the help, I fixed the major bug and now the DRS Patcher is working, am adding a few last minute touches and am gonna have some bugs help me beta test it.

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.