Hi,
I am writing a C code to add two matrices. I want to take input with a feel of real martice, some thing like
1 2 3
4 5 6
7 8 9
but the Scanf function automatically enter EOL and hence my input looks some thing like this,
1
2
3
4
5
6
7
8
9
any idea how to get this thing straight?
Here is the Code :
-
-
// Write a program to add two matrices.
-
-
#include <stdio.h>
-
#include <conio.h>
-
-
void main()
-
-
{
-
int row,column,**ptrA,**ptrB,**ptrC,counter1,counter2;
-
clrscr();
-
-
printf("Enter the number of row of the matrices to be processed:");
-
scanf("%d",&row);
-
-
printf("\nEnter the number of columns of the matrices to be processed:");
-
scanf("%d",&column);
-
-
ptrA=(int**)(calloc(row,sizeof(int *)));
-
ptrB=(int**)(calloc(row,sizeof(int *)));
-
ptrC=(int**)(calloc(row,sizeof(int *)));
-
-
for (counter1=0;counter1<row;counter1++)
-
{
-
*(ptrA+counter1)=(int*)(calloc(column,sizeof(int)));
-
*(ptrB+counter1)=(int*)(calloc(column,sizeof(int)));
-
*(ptrC+counter1)=(int*)(calloc(column,sizeof(int)));
-
}
-
-
printf("\n\n\nEnter the values for First Matrice:\n\n\n");
-
-
for (counter1=0;counter1<row;counter1++)
-
{
-
for (counter2=0;counter2<column;counter2++)
-
{
-
-
printf(" \t");
-
-
scanf("%d",**((ptrA+counter1)+counter2));
-
-
-
}
-
printf("\n");
-
}
Replies would be greatly appreciated!
--
Theprofoundgeek
P.s : Not - so - profound after this problem