If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Need Help with 2D arrays and functions

Originally Posted by Paul McKenzie

You need to destroy the array at the end. Without that, you have a memory leak, and you also won't show your teacher you know how to dispose of the allocated memory.
Aren't you just supposed to pass the int** to the function and work with it inside that function?

Regards,

Paul McKenzie

Hey Paul, thank you for the reply. Yes that is exactly what I'm supposed to do. I'm new to the whole programming area and this is the first language I'm learning. So I'm sorry if my last post didn't make any sense. I'm not so familiar with the terms.

Anyways, can you please show me how to do it. I've been researching all day, and I can't figure out how to do that on my own. And also there might be some unnecessary code in the find_greatest_product function. I'd be glad if you can also remove that, and post the modified code below,

Re: Need Help with 2D arrays and functions

What happens if argc < 5? You haven't tested for the error conditions mentioned in the assignment.

Your fillArray sets the initial values. But your showArray also sets values in the array! Shouldn't showArray just show the values and not also change values?

Code:

tmpfile.getline(line, 10, ' ');

This will read a line from the file stream associated with tmpfile. But you don't open a file anywhere! From where did you get this code for find_greatest_product? Its based upon a 20x20 array read from a file - whereas for your program the size of the array is entered on the command line and fillArray sets the values of the array rather than reading from a file! You need to get rid of this code that reads from a file and change the loop conditions to refer to the rows and cols variables passed to the function as indicated in Paul's post.

where to insert cout statements so that the function will output the max product based on the user input?

When the function has finally calculated the maximum value!

Last edited by 2kaud; June 1st, 2013 at 08:04 AM.

All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
C, C++ Compiler: Microsoft VS2015