I have been working on a HW assignment for a while and I cant figure out how to print out a 'user' selected column out of an array. I can print the rows, but I need to know how to print specific columns dictated by user input.
My code is below.
void showRow(int* array, int = 10){
int i;
printf("Running showRow/n");
for(i=0; i<10; i++){
printf("%d ,", array[i]);
}
printf("\n");
return;
}
int main()
{
int numArray [10][10], row, col, count = 0;
int x = 3;
int *xptr;
/*
int *rowptr = &j;
int *colptr = &k;
*/
for (row=0; row<10; row++){
for(col=0; col<10; col++){
numArray[row][col] = count++;
}
}
printf("pass each row\n");
/*passing each row to my showRow function*/
for(row=0; row<10; row++){
showRow(numArray[row], 10);
}
return 0;
/*
Here is where I am having my trouble. In class we developed a formula to search through the array for our 'col' values
- *((xptr + row * number of Col per row) + col) -
I expect that I need to create a for loop in a for loop to cycle through the rows to find the col's.
And then call the equation.
And then set up my print.
But I dont know what syntax i would use to print!??
printf("col/n");
for (row=0; row<10; row++)
*/
}
I would apprecaite any help. Thanks