D
david
Hello, I am getting some problems with C and how it handles the
pointers. I will tell more about the situation: I have created my own
structure for making one way linked list. I have procedure int
createList(child *root) [child is that structure] and before that I
create pointer child *rootA, and then I invoke createList(rootA)
[*rootA holds the value, and rootA is the pointer, holds the address
as I remember]. And this function creates dynamic list, but the
problem is that rootA does not point to it. After creating list
function returns the length of it.
The question is, how should I send to function a pointer, create a
list in heap and then make that pointer to point to it?
It would be something like this:
int main {
int *item;
func(*item);
printf("%d", *item);
return 0;
}
func(int *num) {
num = malloc(sizeof(int));
*num = 8;
printf("%d", *num);
printf in func gives "8", but item still does not point to the same
memory where that number is located. But I want it to point. How?
}
pointers. I will tell more about the situation: I have created my own
structure for making one way linked list. I have procedure int
createList(child *root) [child is that structure] and before that I
create pointer child *rootA, and then I invoke createList(rootA)
[*rootA holds the value, and rootA is the pointer, holds the address
as I remember]. And this function creates dynamic list, but the
problem is that rootA does not point to it. After creating list
function returns the length of it.
The question is, how should I send to function a pointer, create a
list in heap and then make that pointer to point to it?
It would be something like this:
int main {
int *item;
func(*item);
printf("%d", *item);
return 0;
}
func(int *num) {
num = malloc(sizeof(int));
*num = 8;
printf("%d", *num);
printf in func gives "8", but item still does not point to the same
memory where that number is located. But I want it to point. How?
}