return sus arrays
This commit is contained in:
parent
34f0e8ec34
commit
ce38ddb276
61
index.c
61
index.c
|
@ -10,17 +10,17 @@ int random_number(int lower, int upper);
|
||||||
void print_matrix(int matrix[GRID_SIZE][GRID_SIZE]);
|
void print_matrix(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void induce_noise(int matrix[GRID_SIZE][GRID_SIZE]);
|
void induce_noise(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void parity_check(int matrix[GRID_SIZE][GRID_SIZE]);
|
void parity_check(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void error_check(int matrix[GRID_SIZE][GRID_SIZE]);
|
int error_check(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
|
|
||||||
void parity_check_1(int matrix[GRID_SIZE][GRID_SIZE]);
|
void parity_check_1(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void parity_check_2(int matrix[GRID_SIZE][GRID_SIZE]);
|
void parity_check_2(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void parity_check_3(int matrix[GRID_SIZE][GRID_SIZE]);
|
void parity_check_3(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void parity_check_4(int matrix[GRID_SIZE][GRID_SIZE]);
|
void parity_check_4(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
|
|
||||||
void error_check_1(int matrix[GRID_SIZE][GRID_SIZE]);
|
int * error_check_1(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void error_check_2(int matrix[GRID_SIZE][GRID_SIZE]);
|
int * error_check_2(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void error_check_3(int matrix[GRID_SIZE][GRID_SIZE]);
|
int * error_check_3(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
void error_check_4(int matrix[GRID_SIZE][GRID_SIZE]);
|
int * error_check_4(int matrix[GRID_SIZE][GRID_SIZE]);
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
@ -44,7 +44,6 @@ int main()
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
error_check(message);
|
error_check(message);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -92,12 +91,19 @@ void parity_check(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
parity_check_4(matrix);
|
parity_check_4(matrix);
|
||||||
};
|
};
|
||||||
|
|
||||||
void error_check(int matrix[GRID_SIZE][GRID_SIZE])
|
int error_check(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
{
|
{
|
||||||
error_check_1(matrix);
|
int * sus_array_1 = error_check_1(matrix);
|
||||||
error_check_2(matrix);
|
int * sus_array_2 = error_check_2(matrix);
|
||||||
error_check_3(matrix);
|
int * sus_array_3 = error_check_3(matrix);
|
||||||
error_check_4(matrix);
|
int * sus_array_4 = error_check_4(matrix);
|
||||||
|
|
||||||
|
printf("(%i, %i)\n", sus_array_1[0], sus_array_1[1]);
|
||||||
|
printf("(%i, %i)\n", sus_array_2[0], sus_array_2[1]);
|
||||||
|
printf("(%i, %i)\n", sus_array_3[0], sus_array_3[1]);
|
||||||
|
printf("(%i, %i)\n", sus_array_4[0], sus_array_4[1]);
|
||||||
|
|
||||||
|
return 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,7 +240,7 @@ void parity_check_4(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void error_check_1(int matrix[GRID_SIZE][GRID_SIZE])
|
int * error_check_1(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int col_1[GRID_SIZE], col_3[GRID_SIZE];
|
int col_1[GRID_SIZE], col_3[GRID_SIZE];
|
||||||
|
@ -259,15 +265,17 @@ void error_check_1(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
|
|
||||||
if ((counter % 2) != 0)
|
if ((counter % 2) != 0)
|
||||||
{
|
{
|
||||||
printf("Error in col 1 or col 3\n");
|
static int sus[2] = {1, 3};
|
||||||
|
return sus;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Message is unharmed.\n");
|
static int sus[2] = {-1, -1};
|
||||||
|
return sus;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
void error_check_2(int matrix[GRID_SIZE][GRID_SIZE])
|
int * error_check_2(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int col_2[GRID_SIZE], col_3[GRID_SIZE];
|
int col_2[GRID_SIZE], col_3[GRID_SIZE];
|
||||||
|
@ -292,15 +300,17 @@ void error_check_2(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
|
|
||||||
if ((counter % 2) != 0)
|
if ((counter % 2) != 0)
|
||||||
{
|
{
|
||||||
printf("Error in col 2 or col 3\n");
|
static int sus[2] = {2, 3};
|
||||||
|
return sus;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Message is unharmed.\n");
|
static int sus[2] = {-1, -1};
|
||||||
|
return sus;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
void error_check_3(int matrix[GRID_SIZE][GRID_SIZE])
|
int * error_check_3(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int row_1[GRID_SIZE], row_3[GRID_SIZE];
|
int row_1[GRID_SIZE], row_3[GRID_SIZE];
|
||||||
|
@ -322,17 +332,20 @@ void error_check_3(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
counter++;
|
counter++;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
if ((counter % 2) != 0)
|
if ((counter % 2) != 0)
|
||||||
{
|
{
|
||||||
printf("Error in row 1 or row 3\n");
|
static int sus[2] = {1, 3};
|
||||||
|
return sus;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Message is unharmed.\n");
|
static int sus[2] = {-1, -1};
|
||||||
|
return sus;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
void error_check_4(int matrix[GRID_SIZE][GRID_SIZE])
|
int * error_check_4(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
{
|
{
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
int row_2[GRID_SIZE], row_3[GRID_SIZE];
|
int row_2[GRID_SIZE], row_3[GRID_SIZE];
|
||||||
|
@ -357,10 +370,12 @@ void error_check_4(int matrix[GRID_SIZE][GRID_SIZE])
|
||||||
|
|
||||||
if ((counter % 2) != 0)
|
if ((counter % 2) != 0)
|
||||||
{
|
{
|
||||||
printf("Error in row 2 or row 3\n");
|
static int sus[2] = {2, 3};
|
||||||
|
return sus;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Message is unharmed.\n");
|
static int sus[2] = {-1, -1};
|
||||||
|
return sus;
|
||||||
};
|
};
|
||||||
};
|
};
|
Loading…
Reference in a new issue