I'm new to C but I've programmed in pascal a few weeks ago. In pascal, if you want to change an arrays data, you pass by reference, by typing var myArray
essentially. I can't figure out how to do this in C. I've read a ton of questions but none seem to work. Here's what I have so far.
void set_up_elements(char (*array_to_populate)[20])
{
char* buffer;
FILE *f;
f=fopen("elementList.txt","r");
char copied_text[118][20];
int i=0;
while (!feof(f))
{
fgets(copied_text[i],80,f);
++i;
}
//Close the file to free up memory and prevent leaks
fclose(f);
f = NULL;
}
Here is my code to populate the array, i read a list of the elements in the periodic table in to the array copied_text
. This part works, it successfully populates the array that is INSIDE the function.
int main()
{
char element_array[118][20];
set_up_elements(element_array);
<..>
}
This is how i'm trying to call it. The contents of the array element_array
doesn't change. Does anyone know how to fix this? Thanks.