I need to write a code that receive from the user numbers (must use with EOF) and store them into a matrix.
There are some more requirements:
1. Matrix must be only N*N size, while N will be defined at top.
2. If user is trying to enter more than a N*N numbers, system will throw him out with an appropriate message.
3. If user provide less than a N*N numbers, system will throw him out with an appropriate message.
4. If one of the values (or more) is not an integer, system will throw him out with an appropriate message.
5. Must add a function that will check if the matrix is a magic matrix or not.
6. The program needs to be split into a several functions (Input, Output, Printing, Testings, etc...).
As the base of the program I tried this:
#include <stdio.h>
#include <stdlib.h>
#define N 4
int main()
{
int matrix[N][N];
static int i=0, j=0, counter=0;
int num;
while ( (scanf("%d",&num)) != (EOF) )
{
if ( (i>N) && (j>N) )
{
printf("Sliding Error !");
exit(0);
}
else if ( (i!=N) && (j==N) )
{
matrix[i][j]=num;
i++;
counter++;
}
else if ( (i==N) && (j!=N) )
{
matrix[i][j]=num;
j++;
counter++;
}
}
Next step, will be taking the whole block under the while:
if ( (i>N) && (j>N) )
{
printf("Sliding Error !");
exit(0);
}
else if ( (i!=N) && (j==N) )
{
matrix[i][j]=num;
i++;
counter++;
}
else if ( (i==N) && (j!=N) )
{
matrix[i][j]=num;
j++;
counter++;
}
and store it in a checking function...
But for now I just want it to work as well, because when I'll hold the matrix fill as well, I'll be able to manipulate everything I'd like to...
Please help...
Thanks !!