0

SO my professor gave my a header file with declared functions that are not defined. Here are the 2 that i am working with:

/*
Builds a Two Dimensional array of the given size
  -- cols: The number of columns in the matrix
  -- rows: The number of rows in the matrix
  -- **matrix: A pointer to a matrix to be built, which is not initialized yet, but merely declared before being a parameter here.
  -- returns a ponter to a pointer to a char, which is the pointer to the matrix
*/
char ** build_matrix(int rows, int cols)
{

}


/*
Fills a matrix from std in (command line terminal input)
  -- cols: The number of columns in the matrix
  -- rows: The number of rows in the matrix
  -- **matrix: The matrix to be filled
  -- Should simply accept input via cin or getline, etc.
*/
void fill_matrix(int rows, int cols, char **matrix)
{

}

I am also supposed to compile with: g++ *.cpp -o test And then run my program using: test < sample_input.txt

test < sample_input.txt: this is supposed to use sample_input.txt and cin. So when you use cin it will go to the txt file and use that as input.

Here is the txt file:

5 5
r g p g p
k p o f z
q d x s t
v y r y j
e w y t e
dog

7 7
u c d z q c y
k i m i f z e
k r u c s i p
h o a w b y w
n m o b h o y
s q j e r i x
w u n t g a x
bark

11 11
b r o r t u h q v v q
k k w e o y l a m h d
w k f h q y t y j b q
r h k t m s q l s k q
g t z a y g i w t v z
z n o e v m y m p w b
r v a w n c l q j r o
b x o k f v w o s o i
r j y k z x c t n x s
q g y d v p g g r k c
k m p a i y u w r e o
theweatherisnice

4 8
1 0 1 0 1 1 1 0
0 0 1 1 1 1 0 1
1 0 0 1 0 1 1 0
1 1 0 1 0 1 1 1
111100

In main I cin >> row and col and that will use the first 2 numbers as row and col. Then I will pass that into my function to build my array.

My question is, how do I build the array? and how to fill?

Spencer Apel
  • 31
  • 2
  • 11
  • *My question is, how do I build the array? and how to fill?* It's time to learn the language from [a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – R Sahu Feb 01 '18 at 21:02
  • I know how to build an array, but when it comes to 2d dynamically allocated arrays and pointers I get confused. And I havent found many good tutorials or explinations – Spencer Apel Feb 01 '18 at 21:05
  • A book would help. I feel discouraged that your professor chooses to use `char**` for a matrix. The days of dealing with dynamically allocated memory for arrays are long gone. A `std::vector>` is what you would use if you weren't forced to use `char**`. Good luck. – R Sahu Feb 01 '18 at 21:11

0 Answers0