Question: Fill a 2D aray from a text file. I have created a project that reads data from a text file. The first number on the
Fill a 2D aray from a text file.
I have created a project that reads data from a text file. The first number on the text file is the size of the 2D array. I have two functions. The first getSize() gets the first number from the text file and returns it to initialise the array with correct size. The seciond function fillArray() fills the array. Currently my solution is not working properly. After the 1st row the data is incorect.
CODE
#include
int getSize() { FILE * pointer; int count; pointer = fopen("../testTest.txt", "r"); if(pointer == NULL) { printf("Open operation failed."); return 1; } fscanf(pointer, "%i", &count); return count; }
void fillArray(int array[100][100]) { FILE * pointer; int i, j, x, y, count; pointer = fopen("../testTest.txt", "r"); fscanf(pointer, "%i", &count); for(i = 0; i
int main() { int x, y, size = 0; size = getSize(); int myArray[size][size]; fillArray(myArray); printf("size = %i ",size); for(x = 0; x
TEST DATA file is testTest.txt
3 1 2 3 4 5 6 7 8 9
OUTPUT

ay solver/arraysolver/fillArray Fopen/Debug && /fillArrayFopen size 3 1 2 3 3 2083168336 32767 1422478048 3 1422478016 Udzs-MBP :Debug Dovetales$
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
