Hello,
I am trying to write a simple program that calls a function that takes in a file pointer for a txt document containing the different 'donation' values in a bank to collect to buy a nintendo game.
I am trying to scan all the integer values in the txt file and store it into an array. The last number in the doc is ALWAYS going to be zero, thats guaranteed, thats what determines the end of the list. After I scan all the values and store them into an array, I am trying to print them out to the screen as a 'test' before I go any further with my program...
Can someone help me please?
Right now, after I try scan all the values in the .txt document and try to access for example SLOT number 2 in the array, it gives me an address or some garbage value when I try to print it to the screen.
txtfile- Nintendo.txtCode:#include <stdio.h> #define GAME 50 int TotalDonations(FILE *ifp); int main (void) { FILE *ifp; ifp=fopen("nintendo.txt", "r"); TotalDonations(ifp); system("PAUSE"); return 0; } int TotalDonations(FILE *ifp){ int num; int donations[100], i=0; while(donations[i]!=0){ fscanf(ifp, "%d", &donations[i]); i++; } printf("%d\n", donations[i]); }
3
7
2
4
5
6
7
3
2
2
10
2
3
0