Print jagged array in table format

mojeaux
mojeaux used Ask the Experts™
on
How do you print a jagged array in table format?  Please see code below where I'm obtaining the values from the user but having trouble setting up the display using the printf function.  Here's a snippet of code.   If you need all, please let me know.   Thanks, M

/*~~~~~~~~~~~~~~~~~ buildTable Function ~~~~~~~~~~~~~~~
Create dynamic two dimensional array of pointers which
point to an array of integers.  This function was obtained
from our textbook.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
int** buildTable (void)
{
/*FUNCTION DECLARATIONS*/

/* LOCAL DECLARATIONS */
int rowNum;
int colNum;
int **table;
int row;

/* STATEMENTS */
printf("\n\nSTEP 3:  CREATE A DYNAMIC TWO DIMENSIONAL ARRAY.\n\n");
printf("\nEnter the number of rows in the table:   ");
scanf_s("%d", &rowNum);
table = (int**) calloc(rowNum +1, sizeof(int*));
for (row=0; row<rowNum; row++)
{
      printf("Enter number of integers in row %d:  ", row+1);
      scanf_s("%d", &colNum);
      table[row] = (int*) calloc(colNum + 1, sizeof(int));
      table[row] [0] = colNum;
}
table[row] = NULL;
return table;
}/* create dynamic two dimensional array*/


/*~~~~~~~~~~~~~~~~~ fillTable Function ~~~~~~~~~~~~~~~
Fill the array rows with integers
This function was obtained from our textbook.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void fillTable (int **table)
{
/*FUNCTION DECLARATIONS*/

/* LOCAL DECLARATIONS */
int row = 0;
int column;

/* STATEMENTS */
printf("\n\n~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~~");
printf("\n\nNow fill in the table.\n");
printf("\nFor each row enter the integer and press return.");
printf("\nEnter the number of rows in the table:   ");
printf("\n\n~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~~~");

while (table[row] != NULL)
{
      printf("\n row %d (%d integers) ===>  ", row + 1, table[row][0]);
      for (column = 1; column <= *table[row]; column++)
            scanf("%d", table[row] + column);
            row++;
}
printf("\n\n");
printf("You entered the following integers (table format):\n\n");
while (table[row] != NULL)
{
      printf("\n row %d ===> ", row + 1, table[row][0]);
      for (column = 1; column <= *table[row]; column++)
            scanf("%d", table[row] + column);
            row++;
}
system("pause");
return;

}/* fill dynamic two dimensional array*/
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Business User
Commented:
I finally get it!!   LOL   Was able to fix my own issue.  

while (table[row] != NULL)
{
      printf("\n row %d (%d integers) ===>  ", row + 1, table[row][0]);
      for (column = 1; column <= *table[row]; column++)
            printf("%5d", *(table[row] + column));
            row++;
}
printf("\n\n");
system("pause");
mojeauxBusiness User

Author

Commented:
Sorry!  but I was able to figure this out shortly after posting.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial