An annoying problem

Started by
12 comments, last by Zahlman 19 years, 11 months ago
I've found the problem... I was using fac2 twice. Now it simply does not display anything.

Does anybody know what I'm doing wrong?

EDIT: Now I think I see (possibly one of) the problem(s). The loops keep on going until the end of the array, which is MUCH farther than the last occupied slot. Still, I don't now how to fix this. Help?

~Thanks
Dakar.

[edited by - Dakar on May 9, 2004 9:27:13 PM]
Advertisement
The loop does not go "to the end of the array"; it goes until the first zero-valued element. If nothing in your array is zero (quite possible; the unused memory is uninitialized and could hold anything), then you have a crash (access violation). What you need to do is remember the count of how many elements are meaningful in there.

Or, you could just use the property that the common factors of two numbers are simply the factors (including itself) of the greatest common factor of the two numbers. Note that there is a well known algorithm for finding GCD''s.

Again, strongly consider std::vector. It will keep track of this resizing/knowing-current-size business for you.

Also, you passed "list" to the factor-finding function the second time as well; I assume you meant to pass "listo" so as to have two separate sets of data to compare.

Also, "real" is a strange name for that function.
quote:Original post by Zahlman
The loop does not go "to the end of the array"; it goes until the first zero-valued element. If nothing in your array is zero (quite possible; the unused memory is uninitialized and could hold anything), then you have a crash (access violation). What you need to do is remember the count of how many elements are meaningful in there.


Thanks, I''ve now made sure the last needed array space is null.

quote:Or, you could just use the property that the common factors of two numbers are simply the factors (including itself) of the greatest common factor of the two numbers. Note that there is a well known algorithm for finding GCD''s.


I see. I''ll try and work that in.

quote:Again, strongly consider std::vector. It will keep track of this resizing/knowing-current-size business for you.

Also, you passed "list" to the factor-finding function the second time as well; I assume you meant to pass "listo" so as to have two separate sets of data to compare.

Also, "real" is a strange name for that function.


Sorry, but I don''t know what a vector is in C++.

The list thing was the problem. Now it works perfectly. Thanks!

Real was short for "Realize", though I have no idea why I wanted it to be calld that. I changed its name to factor.

Thanks again!
~Dakar.

std::vector OMFG!!!11

Have fun.

This topic is closed to new replies.

Advertisement