I'm a little lost when it comes to initializing a dynamic array. I am counting the number of integers that appear in a given text file and incrementing a counter which will then be used to set the size of the array. Here is what I have so far:
i = 0; int val; for(i=0; fscanf(dFile, "%1d", &val ) == 1; i++) printf(" val: %d\n", val); printf("i is: %d\n", i); //Dynamic Array // Defining a dynamic array of n ints: int n = i; int *numbers = malloc(n * sizeof(int)); //numbers[n]; i = 0; //int numbers; readNumbers(numbers, i);
Not sure what I'm missing and I can't seem to find anything online that would help me figure it out. Any help/input would be greatly appreciated!