K
Keith Thompson
Bill Cunningham said:snip]
Every element of buf that you have defined is zero. Thus, adding them
to sum should always produce zero.
int buf[128]={0}; Make 128 ints equal 0 ? Making sure.
Yes.
Why do you expect sum to ever have a value other than zero? Why is sum
the loop control for the iteration, rather than i?
I don't think I'm sure of the engineering done here.
I'm not sure I'd call it engineering, and I'm not sure how to help
other than by just showing you the correct code.
This looks exactly like the usual idiom for summing the members of an
array, except that instead of counting until your loop counter reaches
the end of the array ("i < 128"), you count until the sum reaches a
particular value. Why?
That last line under for always confuses me. If int buf[128]={0}; works
for all elements that should be all I need.
The declaration of buf is just fine. It's what you (try to) do with
it later that's biting you.