E. Inazaki
2013-03-30 18:38:01 UTC
Hello,
I have a simple program that prints and does scalar multiplication on a
2d array. The program is split between two files, here they are:
======= The main file =====
#include <stdio.h>
int main(void) {
void scalarMultiply(int matrix[3][5], int scalar);
void displayMatrix(int matrix[3][5]);
int sampleMatrix[3][5] =
{
{7, 16, 55, 13, 12},
{12, 10, 52, 0, 7},
{-2, 1, 2, 4, 9}
};
displayMatrix(sampleMatrix);
scalarMultiply(sampleMatrix, 2);
displayMatrix(sampleMatrix);
scalarMultiply(sampleMatrix, -1);
displayMatrix(sampleMatrix);
return 0;
}
======= The functions file =======
#include <stdio.h>
void scalarMultiply(int matrix[3][5], int scalar) {
int row, column;
for(row = 0; row < 3; ++row)
for(column = 0; column < 5; ++column)
matrix[row][column] *= scalar;
}
void displayMatrix(int matrix[3][5]) {
int row, column;
for(row = 0; row < 3; ++row) {
for(column = 0; column < 5; ++column)
printf("%5i", matrix[row][column]);
printf("\n");
}
}
I'm using version 1.7 of the debugger. My problem is that if I place a break
in the main, I can view the entire contents of the array but if my break is
somewhere in the functions I can only see part of it (looks like just the first
row). Why is that and how can I examine the entire array from the functions?
TIA
eric
I have a simple program that prints and does scalar multiplication on a
2d array. The program is split between two files, here they are:
======= The main file =====
#include <stdio.h>
int main(void) {
void scalarMultiply(int matrix[3][5], int scalar);
void displayMatrix(int matrix[3][5]);
int sampleMatrix[3][5] =
{
{7, 16, 55, 13, 12},
{12, 10, 52, 0, 7},
{-2, 1, 2, 4, 9}
};
displayMatrix(sampleMatrix);
scalarMultiply(sampleMatrix, 2);
displayMatrix(sampleMatrix);
scalarMultiply(sampleMatrix, -1);
displayMatrix(sampleMatrix);
return 0;
}
======= The functions file =======
#include <stdio.h>
void scalarMultiply(int matrix[3][5], int scalar) {
int row, column;
for(row = 0; row < 3; ++row)
for(column = 0; column < 5; ++column)
matrix[row][column] *= scalar;
}
void displayMatrix(int matrix[3][5]) {
int row, column;
for(row = 0; row < 3; ++row) {
for(column = 0; column < 5; ++column)
printf("%5i", matrix[row][column]);
printf("\n");
}
}
I'm using version 1.7 of the debugger. My problem is that if I place a break
in the main, I can view the entire contents of the array but if my break is
somewhere in the functions I can only see part of it (looks like just the first
row). Why is that and how can I examine the entire array from the functions?
TIA
eric