I’ve got a piece of code:
void Read(int T[], int len) {
int i;
T = (int*) malloc(len * sizeof *T);
for (i=0;i<len;i++) {
scanf("%d", &T[i]);
}
}
I use in this way:
int *T;
Read(T,len);
Next, I wanna write my table:
void Write(int T[], int len) {
int i;
for(i=0;i<len;i++) {
printf("%d, ", T[i]);
}
printf("\n");
return;
}
And use it:
Write(T,len);
It gives me wrong results. I almost sure that problem is connected with ‘&‘ but I cannot deal with it.
Thanks in advance
One problem may be that you’re modifying a local variable
Tinside yourReadfunction:The
TinsideReadis a copy of the realTvariable. You assign a new value to the copy, but the original remains unchanged.To actually modify the outer
T, pass a pointer to it like so: