k is uninitialized! for (int k=0; ...)