So given the following code (not my actual code since it would add unnecessary lines):

typedef struct block{
    int a;
    int table[64];
}block;

typedef block* block_ptr;

void getValues(block_ptr node){
    int i, j;
    for(i=0; i<5; i++){
        for(j=0; j < 15; j++){
            node[i].table[j] = j;
        }
    }   
}

int main(){
    block node[10];
    getValues(node);
    printf("%d\n", node[4].table[2]);
    return 0;
}

Why does it print out garbage values instead of, in this case, 2? And how can I fix this issue? Thank you for your time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.