daviddoria 334 Posting Virtuoso Featured Poster

In a real situation, you would definitely want to use an std::vector and sort() from STL algorithm:

http://www.cplusplus.com/reference/algorithm/sort/

I'm not sure if that is allowed in your assignment, though.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You were on the right track by including sstream, but then you didn't use it!

Long lists of code like this this:

if (IPd == ip0) {
			k = 0;
			f0.open ("Node0.txt"); 
			f0 << "I received a packet from Node " << i << "\n"; // write all the packets that node0 recived and from where
		}
		else if (IPd == ip1) { 
			k = 1;
			f1.open ("Node1.txt");
			f1 << "I received a packet from Node " << i << "\n";
		}

is almost always a bad idea.

Assume IP is an int (0, 1, ... 15). You can replace about 100 lines with simply:

stringstream ssFileName;
ssFileName << "Node" << IP << ".txt";

f0.open (ssFileName.str()); 
f0 << "I received a packet from Node " << IP << "\n";

Hope that helps,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

There are literally hundreds of tutorials about pointers online. I'd recommend reading as many as you can and asking here if you have specific questions.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd recommending changing the title of your post. This isn't really that easy of a question (at least to me, haha). You should call it "Detecting splits in a btree"

Dave

Ancient Dragon commented: Agree. Not an easy question to me either. +28
daviddoria 334 Posting Virtuoso Featured Poster

My suggestion is to not use OpenGL directly, but rather, use VTK! (http://vtk.org/)

I have been working hard for the last year writing examples, which you can find here: http://www.vtk.org/Wiki/VTK/Examples

There is certainly a learning curve (but there is with OpenGL, too, as you're experiencing), but it's much cleaner than OpenGL once you get the hang of it.

Good luck,

Dave

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

In the constructor, you would probably want to set all of the coefficients to 0. The idea is just that you really NEVER want to have unassigned variables. What if you forgot they were assigned in the read function and tried to access them before that? You would end up with a junk value.

Dave

gnarlyskim commented: very clear in explanations +1
daviddoria 334 Posting Virtuoso Featured Poster

This was just a goof on my part, but it was quite annoying and maybe it could be handled a bit better. I was on a different machine than normal, so I was not logged into daniweb but I didn't realize it. I found an interesting post and spent quite a while writing a reply. When I clicked "post a quick reply" it told me that I was not logged in (correctly). When I clicked "back", my reply was gone (the text box was empty). Is there a way to have the text remain in the box in a case like this?

Thanks,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Some libraries that you may find helpful:

ITK:
http://itk.org/

VIL (part of VXL):
http://vxl.sourceforge.net/

OpenCV:
http://opencv.willowgarage.com/wiki/

CImg
http://cimg.sourceforge.net/

Hope that helps.
Dave

Salem commented: Nice +19
daviddoria 334 Posting Virtuoso Featured Poster

1) The undefined reference is because you are not linking to SaveData.cpp. Which IDE are you using (Visual studio, etc)?

2) 'retreive' should be spelled 'retrieve'.

3) you seem to still be using the 5th element (element 4), when it is not valid.

4) it seems to work just fine when you change void outputSavedata (int* stats); to void outputSavedata (int stats[4]);

daviddoria 334 Posting Virtuoso Featured Poster

Sorry, we will not just do your assignment for you. We also cannot teach you all of c++ - you're going to have to give it an attempt and we can help when you run into problems.

daviddoria 334 Posting Virtuoso Featured Poster

getch() is a c language thing:
http://www.daniweb.com/forums/thread11811.html

I think that book was wanting you to include conio.h, but as you will see if you are working in c++ you likely shouldn't be using that.

daviddoria 334 Posting Virtuoso Featured Poster

You cannot just post a bunch of code and expect us to do your assignment.
1) use code tags so the code you do post is readable
2) extract the problem you are having in to the smallest example possible ( < 20 lines) with sample input, expected output, current (incorrect) output, and any errors that are generated)

Salem commented: Damn straight! +36
daviddoria 334 Posting Virtuoso Featured Poster

peter, please use descriptive thread titles in the future :)

tux4life commented: Yes, same came to my mind :) +11
daviddoria 334 Posting Virtuoso Featured Poster

Yea, I think that generally the convention is to not include .cpp files. Surely you can make a project with any IDE. CMake is becoming pretty popular - it is a "crossplatform project building" utility - that is, in linux, you can generate a makefile or a KDevelop project. In windows you can generate a visual studio project. It's much much easier than writing makefile yourself for large projects, but for this small of a project I'm sure you could find a makefile tutorial online (this one looks reasonable http://www.opussoftware.com/tutorial/TutMakefile.htm)

Dave

tux4life commented: Yes, that one looks reasonable :) +8
daviddoria 334 Posting Virtuoso Featured Poster

I believe the preferred method of reading all the lines in a file is this:

std::string line;
	
while(getline(fin, line))
{
	//the current line is now in "line", handle it
}
daviddoria 334 Posting Virtuoso Featured Poster

Can you abstract the question to something like "how do you input everything the user types until the enter key is pressed?" or something like that? I'd say 3/4 of those lines are not related to your question. Please post
1) the shortest example possible that demonstrates the problem
2) a sample input
3) the current output
4) the expected output

and then we can probably help :)

Dave

tux4life commented: Agreed :) +7
daviddoria 334 Posting Virtuoso Featured Poster
newcook88 commented: Thank you for the link i wud appreciate if u can show a method to print the output that vector +1
daviddoria 334 Posting Virtuoso Featured Poster

Here are some of the answers:

What is the output of printf("%d")

It will output some junk signed integer value because you never told it which signed integer to output.

Difference between "vector" and "array"?

A vector is a STL container that has the same functionality as an array, but you check the validity of an index using .at() and you can get the length with .size(). You can also use STL iterators to potentially convert a vector into a different STL container.

Can we generate a C++ source code from the binary file?

Sounds hard, if not impossible.

What are inline functions?

Functions that the compiler knows to optimize. I think most compiler usually figure out what to inline by themselves these days.

Details about profiling?

I use valgrind's cachegrind. Works really well/easily.

tux4life commented: Nice explanation ! +1
daviddoria 334 Posting Virtuoso Featured Poster

Not very efficiently, you could simply push the front() element onto the back of the queue, then pop it from the front. Do this until you get to the last element, but simply pop it instead of pushing and popping it. Because of the 'remark' I take it that this is an assignment and therefore you aren't worried about efficiency, just getting it work. Let me know if that's an acceptable solution.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

if you have a very simple program that just has to run a zillion times, you can use OpenMP parallel for loops. You just put a #pragma right before the loop and it magically splits it across all available cores.

You can do more complicated things with openmp, but this is what I use it for.

Dave

Ancient Dragon commented: Excellent :) +36
tux4life commented: Nice to know, I didn't know it ... +1
daviddoria 334 Posting Virtuoso Featured Poster

Cool, that'll do it. I sorted the points and then used unique.

sort(Points.begin(), Points.end());
	vector<Point>::iterator new_end = unique(Points.begin(), Points.end());
	Points.erase(new_end, Points.end());

Thanks all.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You seem to have not tried at all. Give it a shot and then if it doesn't work we'll help you.

Salem commented: Quite so +29
daviddoria 334 Posting Virtuoso Featured Poster

But look how easy this is!

ifstream fin(Filename.c_str());

	if(fin == NULL)
		cout << "Cannot open file." << endl;

	vector<string> Lines;
	string line;
	
	while(getline(fin, line))
	{
		Lines.push_back(line);
	}
	
cout << "NumLines: " << Lines.size() << endl;

	for(unsigned int i = 0; i < Lines.size(); i++)
		cout << Lines[i] << endl;
daviddoria 334 Posting Virtuoso Featured Poster

Is there a way to remove these threads altogether? It really pollutes the forums.

Dave

mitrmkar commented: Well said ... +6
daviddoria 334 Posting Virtuoso Featured Poster

you could use a vector instead of an array

#include <vector>

then you can return a vector<int> and not have to worry about every saying pointer!

Dave

Salem commented: Definitely the best idea +25
daviddoria 334 Posting Virtuoso Featured Poster

I am using VS2008. Turns out I was using a library that was using the 80 version of the file.
I used this
http://www.dependencywalker.com/

and it showed me exactly what the problem was! Highly recommended and free!!

Sorry for the confusion.

Dave

Ancient Dragon commented: Excellent :) +26