Hello, I'm new to these forums and to C language. I'm writing a code for an algorithm and I'm having problem with my arrays. I believe the problem lies with pointers, since I've never studied them and still don't quite understand how they work.
Here's a section of the code in which I'm noticing problems
so when i run this, the line within the loop prints the correct value for U[0], but as soon as it exits the loop the value for U[0] returns to 0.Code:int U[x]; //set of searched nodes in X int V[y]; //set of searched nodes adjacent to those in U int R[y]; //set of adjacent nodes to those in U step1: //Search X for labels, if all non-zero finish u=0; for(i=0;i<x;i++){ if(X[i].label==0){ U[u]=X[i].id; printf("ID %d into U[%d]\n",U[u],u); //added to see what array does u++; for(z=0;z<y;z++){ V[z]=0; } v=0; break; } else if(i==x-1){ goto finish; } } printf("ID %d into U[%d]\n",U[0],0); //see what values in array
How can I get it to store the values to U within the scope of the method?
Edit: I should probably also mention that the sizes of the arrays (x and y) are read in from a file
Thanks in advance, hope someone can help soon! gotta turn it in in a few hours