Krzysztof Kolago wrote:
I wrote short program:
#include <stdio.h>
main(){
int Uporzadkowana[255][255];
int Tablica[64*1024];
Tablica[0]=1;
for(int i = 0; i < 256; i++){
for(int j = 0; j < 256; j++){
printf("i=%i, j=%i...",i,j);
}
}
printf("%i",Tablica[0]);
}
And "i" and "j" both grow up, but when I've add this line:
Uporzadkowana[j][i]=Tablica[0];
into loop, under printf, "i" is always "0", why???
Hello Chris,
I rewrote your code slightly so that it complies with the C++ standard:
#include <cstdio>
using std::printf;
int main() {
int Uporzadkowana[255][255];
int Tablica[64*1024];
Tablica[0]=1;
for(int i = 0; i < 255; i++){
for(int j = 0; j < 255; j++){
printf("i=%i, j=%i...",i,j);
Uporzadkowana[j][i]=Tablica[0];
}
}
printf("%i",Tablica[0]);
}
Also note that I changed the loop conditions to "i < 255" and "j < 255."
Each dimension of the two-dimensional array is 255 elements, indexed from 0
to 254. 255 is not a valid index.
What happens when you compile and run my version of your program? When I
run it, I get the output you would expect. i is not always 0; it changes
incrementally from 0 to 254.
--
Russell Hanneken
rg********@pobox.com
Remove the 'g' from my address to send me mail.