I have several numbers that i want to insert into Matrix
.
This is how i am get all my numbers one by one:
int i, n;
int ch;
int *arr;
int dimension;
int numbers = 0;
char str[512];
// User input.
fgets(str, sizeof str, stdin);
for (i = 0; i <= (strlen(str)); i++)
{
if (str[i] != '\0' && !isspace(str[i]))
{
int num = atoi(&str[i]);
numbers++;
if (i == 0)
{
dimension = num;
arr = allocatearraysize(dimension);
}
// Here i want to add the current number to my `Maxtix`.
}
}
free(arr);
int* allocatearraysize(int size)
{
return (int *)malloc(size * size * sizeof(int));
}
So i try:
arr[0][0] = num;
only for see if thats works but got an error
:
expression must have pointer-to-object type
Edit
So if my input is 2 1 2 3 4
:
the first number
(2
) means that my matrix
should be 2x2
and i expected 4 numbers
after this number
(2
).
In case the numbers
of number
not match the first number
for example:
3 1 2 3 4
The first number
here is 3 so after this number
i excepted to 9
numbers
so in this case i only want to print error
message.
But any way i want to insert this numbers
into my Matrix
.