What I'm trying to do (not very successfully) is if my code detects a (if(matrix[i][j] ==1))coming signal (1 or 0) for the next few steps, I want my code to be written in a new matrix: newmatrix[i][j]=10and if not continue 0. Here is my code:
for (i = 0; i < rows; i++) {
j = 0;
do {
if (matrix[i][j] == 1) {
int m = j;
while (j < m + 3) {
newmatrix[i][j] = 10;
printf("newmatrix[%i][%i] and %f\n", i, j, newmatrix[i][j]);
j++;
continue;
}
}
if (matrix[i][j] == 0) {
newmatrix[i][j] = 0;
printf("newmatrix[%i][%i] and 0 is %f\n", i, j, newmatrix[i][j]);
j++;
continue;
}
j++;
} while (j < MAXTIME);
}
}
The problem is that if there is a signal near the end, and does not stop when the number of columns reaches the maximum number, the code inserts new columns, although they are only 10:
Where is my mistake can someone point me in the right direction? Could there be a way to make this cleaner using instructions goto?
source
share