I need to access a variable length array i have created on the first line reading from a file. In order to access the array for when i am reading the following lines i would need to initialize it before line 1 is read out side of my conditional statement. but this is before I know the length of the array.
here is an example of my code
int count=0;
while (fgets(line, sizeof(line), fd_in) != NULL) {
if(count==0){
//get wordcount from line
int word[wordcount];
//put line data into array, using strtok()
}else{
//need to access the array here
}
count++;
}
Edit: My question is how should i go about being able to access this array where i need it?
malloc) and pointer to beginning of the array. Also you should not write to the array before it is allocated (declared). Store the info in other place.wordis local inside the scope where it is defined, and can only be accessed inside that scope.