I have this as my struct
struct theFile{
int count;
FILE *fPointer;
int *fileItems[];
}myFile;
This is my method that saves the file in fileItems. It is saving the numbers properly. For example fileItems[0] = 5
, fileItems[1] = 45
, fileItems[2] = 35
void saveFile(){
myFile.fPointer = fopen("mileage.txt", "r");
int i = 0;
while (!feof(myFile.fPointer)){
myFile.fileItems[i] = (int*)malloc(sizeof(int));
fscanf(myFile.fPointer, " %d,", myFile.fileItems[i]);
i++;
}
myFile.count = i;
}
but when I go to print the contents of the file with this method it will print the first number properly but then it will print the rest as large numbers. Can someone please tell me why it isn't printing the correct content of the array.
void viewFile(){
for(int i = 0; i < myFile.count; i++){
printf("%d, ", myFile.fileItems[i]);
}
}
also note, it is being written in c.