Is it possible to have a pointer notation to a variable outside of its scope?
Here is my main:
int main(){
int number[15];
readNumbers();
return 0;
}
Here is my readNumbers() function:
void readNumbers() {
FILE *fp;
fp = fopen("/Users/Documents/testNumbers.txt", "r");
if (fp == NULL) {
printf("File could not be loaded!");
exit(0);
}
if (fp != NULL) {
int c;
while ((c = fgetc(fp)) != EOF) {
putchar(c);
}
fclose(fp);
}
return 0;
}
I'm trying to get my readNumbers() function to add numbers from testNumbers.txt into the array of 15 of type int in my main (int* num[15]
).
Would this work?:
int num[15]; // This will be in the main
&&
numRef *ip; // This will be in the main also as a pointer variable declaration
And then having instead of int c;
in my readScores()
function have this instead?:
ip = int* num[15]; // The variable that will store the address of int in pointer variable
Very, very confused about pointer notation. Help would be awesome! Thanks!