I'm passing a multidimensional array to the function "read_line" but what I'm getting back is only 1D-array, see the code below. What "read_line" do is read the sentence and save every word as an single string in the 2D-array, but when I try to print the 2D-array back in the main function I got only 1D-array, why? Thank you a lot for the help
#include<stdio.h>
#include<string.h>
#define ROW 10
#define COLUMN 10
static char terminating_char;
int read_line(char array_string[ROW][COLUMN], int row_num);
int main() {
int row_num=0;
char array_string[ROW][COLUMN];
printf("Write a sentens: ");
read_line(array_string, row_num);
printf("Reversal of sentence: ");
while (row_num > 0)
printf("%s ", array_string[row_num--]);
printf("%s%c\n", array_string[row_num], terminating_char);
}
int read_line(char array_string[][COLUMN], int row_num) {
char c;
int i=0, j=0;
while ( (c = getchar()) != '\n' && i < ROW)
{
if (c == ' ' || c == '\t') {
array_string[i][j] = '\0';
i++;
j = 0;
continue;
}
if (c == '.' || c == '!' || c == '?') {
terminating_char = c;
array_string[i][j] = '\0';
break;
}
else if (j < COLUMN)
array_string[i][j++] = c;
}
return row_num;
}