Fixed it. thx
I wanted to make an int from char. I used atoi to fix this.
Matrix[i][j]=matrixinput;
What you are doing is assign a char array of size 1 to an int. Your compiler issues a warning for this.
Don't assign arrays like this .
You want to take input in 2-d array, directly take inout in it using scanf -
scanf("%d",&Matrix[i][j]);
And this loop -
while (i<=(sizeint-1) && j<=(sizeint-1)){
This loop won't iterate for once , because condition will remain always flase as sizeint-1 is -1 as sizeint is -1 . So , you need to work on this condition also .
Note - Increase your array's size and don't use gets , use fgets instead.
A professor gave me good tip for debug this type of error, ask you if the left operator type is equals to the right operator type. in your code it's false because right operator equals integer and left operator equals character.
What you could do to remove the error is: Matrix[i][j] = (int) matrixinput[0]; (Array indexing starts with 0)
But your code will still not work because you have initialized i and j to 0 and also sizeint. It means that, in the loop while (i<=(sizeint-1) && j<=(sizeint-1)), you are basically checking if 0 <= -1 which is impossible and so your while loop will never execute. What you could do is:
gets(matrixinput);
for(i = 0; i < 10; i++)
{
for(j = 0; j < 10; j++)
{
if(i == 0 && j == 0) { //say you want to put the char at the first row first column
Matrix[i][j] = matrixinput[0];
}
}
}
You could also use scanf() instead of gets().
here is one possible correction to the posted code
It removes unneeded clutter from the code
It makes use of scanf() so no char to int conversion needed in the code
It consistently indents the code
It #defines the size of the matrix to make the code clearer
Note: it fails to check the returned value (not the parameter value) from scanf() to assure the input/conversion was successful
#define MATRIX_SIZE (10)
// int i=0;
// int j=0;
// char size[1];
// char matrixinput[1];
// int sizeint=0;
//int Matrix[10][10];
int Matrix[MATRIX_SIZE][MATRIX_SIZE];
// while (i<=(sizeint-1) && j<=(sizeint-1)){
// gets(matrixinput);
// Matrix[i][j]=matrixinput;
// j++;
// if (j==(sizeint-1)){
// j=0;
// i++; }
// else {continue;};
//};
for( int i=0; i<MATRIX_SIZE; i++)
{
for( int j=0; j<MATRIX_SIZE; j++)
{
scanf( "%d", Matrix[i][j]);
}
}