#include <stdio.h>
#include <inttypes.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#define ROWS 3
#define COLS 4
void print_matriz(int16_t arr[ROWS][COLS]);
void remover_elemento(int16_t arr[ROWS][COLS], uint8_t, uint8_t);
void app_main() {
int16_t arr[ROWS][COLS] = {{19, 8, 177, 3},
{5, 34, 96, 21},
{100, 2, 73, 546}};
printf("Matriz orginal: \n");
print_matriz(arr);
printf("Remover el emento 1,2 (se remueve el 96). \n");
remover_elemento(arr, 1, 2);
print_matriz(arr);
while (true) {
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void print_matriz(int16_t arr[ROWS][COLS])
{
for (uint8_t r = 0; r < ROWS; r++)
{
for (uint8_t c = 0; c < COLS-1; c++)
{
printf("%" PRId16 ", ", arr[r][c]);
}
printf("%" PRId16 "\n", arr[r][COLS-1]);
}
}
void remover_elemento(int16_t arr[ROWS][COLS], uint8_t row, uint8_t col)
{
if (row >= ROWS || col >= COLS)
return;
uint8_t prev_r = row, prev_c = col;
uint8_t r = row, c = col;
while ( (prev_r < ROWS-1) || (prev_c < COLS-1) )
{
if (++c == COLS)
{
r++;
c = 0;
}
arr[prev_r][prev_c] = arr[r][c];
prev_r = r;
prev_c = c;
}
arr[r][c] = -1;
}