What you're trying to do is to determine at run time how big you 2D array should be. The problem with that is that an array's size has to be known at compile time, which is always before run time.
If you have some a priori information about that maximum amount of data, then you can create a 2D array at compile time that will be big enough.
There is a way to create arrays of arbitrary size at run time, but you have to allocate memory for them from the heap and have a good working knowledge of pointers, which I suspect you don't have.
There are so many things wrong with your program, it would probably be better to start from scratch. That would entail coming up with an algorithm that you understand, and that you would implement in C.
Comments about your code
- int dataArray[2]; -- creates a 1D array that can hold two ints.
- int dimensions[2]; -- creates a 1D array that can hold two ints.
- fread(dimensions, sizeof(dimensions), 1, fp); -- this reads two ints, probably not what you intended.
- float myArray[elements]; -- Absolutely can't do this. The value of elements is not known at compile time, so the compiler has no way of knowing how much memory to allocate for the array. Also, this is an array of float, and dataArray is an array of int. Is the data in the binary file int or float?
- fread(buffer, sizeof(buffer), 1, fp); -- The comment says second header. How many headers are there?
- r = i / dimensions[1]; -- i has never been given a value, so r will be assigned a garbage value. Even if i had been initialized, why would you divide i by dimensions[1]?
- c = i % dimensions[1]; -- As before, i has never been given a value, so c will be assigned a garbage value. Even if i had been initialized, why would you i modulo dimensions[1]? Whatever happened to dimensions[0]?
- dataArray[r][c] = myArray[i++]; -- dataArray is a 1D array, so this generates a compiler error. Even if it had worked, what you would be doing is reading the value at a random place in myArray (since i is a garbage value) and attempting to store it at a random location in dataArray (since r and c are garbage values).
As I already said, I would advise you to scrap you current attempt and start from scratch. You need a good understanding of how the data is layed out in the binary file you program will read. From you code, I have a sense that you don't understand what's in the binary file, which means it will be impossible for you to write a program to process it. Your code mentions a header block, which I assume contains the number of rows and the number of columns. For example, if the header contained 3 and 4, I would expect 12 data values to follow. There would be no need for a footer, and certainly no need for a second header and second footer. You also need to know the type of the data in the binary file, and you seem to be confused about that, declaring an array of int in one place and an array of float in another, both supposedly for the same data.
After you have a good understanding of how the data is laid out in the input file, then you can start in on an algorithm - not code - a description in English of what you're going to do. Once you have a good understanding of what you want the computer to do, then you're ready to start writing code.