Неправильно определяет переменную temp(индекс наименьшего элемента в строке)
В функции coppi неправильно определяет переменную temp(минимальный индекс в строке). Суть задачи: удалить минимальный элемент строки в нечетной строке.
#include <locale.h>
#include <stdlib.h>
void inputRowsCols(int* rows) {
printf("Enter the number of elements of the first array 'Row' ");
while (scanf_s("%d", rows) != 1 || *rows <= 0 || getchar() != ('\n')) {
printf("Enter the number of elements of the first array 'Row' \a");
rewind(stdin);
}
}
int** Matrix(int rows, int cols) {
int** arr;
arr = (int**)calloc(rows, sizeof(int*));//+
for (int i = 0; i < rows; i++) {
arr[i] = (int*)calloc(rows, sizeof(int));
}
if (arr == NULL) {
printf("Ошибка выделения памяти");//ошибка выделения памяти
return 0;
}
return arr;
}
int cols(int** arr, int row) {
int cols = 1;
for (int i = 0;; i++) {
if (arr[row][i] != 0) {
cols++;
}
else {
break;
}
}
return cols;
}
void printMatrix(int** arr, int rows) {
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols(arr, i); j++) {
if (arr[i][j] != 0)
printf("%5d", arr[i][j]);
}
printf("\n");
}
}
void input_Matrix(int** arr, int rows, int* cols) {
for (int i = 0; i < rows; i++) {
int breakk = 0;
for (int j = 0; j < *cols && breakk == 0; j++) {
printf("Input arr[%d][%d]: ", i + 1, j + 1);
while (scanf_s("%d", &arr[i][j]) != 1 || getchar() != '\n') {
if (arr[i][j] == 0) {
break;
}
printf("Enter element, row: %d, cols: %d ->", i + 1, j + 1);
rewind(stdin);
}
if (arr[i][j] == 0) {
breakk = 1;
if (i != rows - 1) {
printf("Next row->\n");
}
}
else {
(*cols)++;
arr[i] = (int*)realloc(arr[i], (*cols) * sizeof(int));
}
}
}
}
void coppi(int** arr, int rows, int* cols) {
for (int i = 0; i < rows; i++) {
if (i % 2 == 1) {
int temp = 0;
for (int j = 1; j < (*cols); j++) {
if (arr[temp] > arr[j]) {
temp = j;
}
}
(*cols)--;
printf("%d", temp);
for (int j = temp; j < (*cols); j++) {
printf("%d", j);
arr[i][j] = arr[i][j + 1];
}
arr[i] = realloc(arr[i], (*cols) * sizeof(int));
}
else {
continue;
}
}
}
int main() {
int rows = 1, cols = 1;
inputRowsCols(&rows);
int** arr = Matrix(rows, &cols);
input_Matrix(arr, rows, &cols);
printf("\n\nYour matrix -> \n");
printMatrix(arr, rows);
coppi(arr, rows, &cols);
printf("\n\nNew matrix -> \n");
printMatrix(arr, rows);
return 0;
}```