# pls help i cant find the problem :(((

• 11-07-2002
condorx
pls help i cant find the problem :(((
Code:

```#include <stdio.h> #include <stdlib.h> typedef int *matrix_member;  void print_matrix(matrix_member matrix,int size) ;  void multiply_matrix(matrix_member m1,matrix_member m2,matrix_member result,int size);  void add_matrix(matrix_member m1,matrix_member m2,matrix_member result,int size);  matrix_member create_matrix(int *size);  matrix_member return_address(int i,int j,matrix_member m,int size);  matrix_member allocate_memory(int num);  int main() {  int size1,size2;  matrix_member matrix1,matrix2,addition_matrix,multiplication_matrix;  //create first matrix  //create second matrix  //print them  //add them and print the result  //multiply them and print the result  matrix1=create_matrix(&size1);  matrix2=create_matrix(&size2);  print_matrix(matrix1,size1);  print_matrix(matrix2,size2);  addition_matrix= allocate_memory(size1);  add_matrix(matrix1,matrix2,addition_matrix,size1);  print_matrix(addition_matrix,size1);  multiply_matrix(matrix1,matrix2,multiplication_matrix,size2);  print_matrix(multiplication_matrix,size2);  return 0; } matrix_member allocate_memory(int num) {   matrix_member t;   t=malloc(sizeof(int)*(num*num));   return (t); } void ask_matrix_size(int *num) {         printf("enter size of matrix:");         scanf("%d",num); } //-------------------problem-------------- void read_matrix(matrix_member matrix,int size) {  int i,j,number;   for(i=0;i<size*size;i++)         {         printf("enter value of matrix:");         scanf("%d",&matrix[i]);         } } //-------------------------------------------------------!!!!!! void  print_matrix(matrix_member matrix,int size) {   int i,j;   for (i=0;i<size;i++)   {   for(j=0;j<size;j++)     printf("%d  ",*return_address(i,j,matrix,size));   printf("\n");   }   printf("\n"); }  matrix_member create_matrix(int *size) {   matrix_member st_matrix;   ask_matrix_size(size);   st_matrix= allocate_memory(*size);   read_matrix(st_matrix,*size);   return(st_matrix); } void  add_matrix(matrix_member m1,matrix_member m2,matrix_member result,int size) {   int i;   for(i=0;i<size*size;i++)           result[i] = m1[i] + m2[i]; } matrix_member return_address(int i,int j,matrix_member m,int size) {     int a;     for(a=0;a<(i*size+j);a++);         m++;         return m; } void  multiply_matrix(matrix_member m1,matrix_member m2,matrix_member result,int size) { }```
the output:

enter matrix size:2
enter value of matrix:1
enter value of matrix:2
enter value of matrix:3
enter value of matrix:4
the output has to be like that:
1 2
3 4

but i cant do this my output is :
2 2
2 2
(the second value of matrix)

how can i fix this problem pls help
i think the problem occurs in the function read_matrix()
• 11-07-2002
Monster
I did not test your program but this might be a problem:
Code:

```matrix_member return_address(int i,int j,matrix_member m,int size) {     int a;     for(a=0;a<(i*size+j);a++);         m++;         return m; }```
You are incrementing m, wich is the original pointer to the matrix. You should create a temp pointer and return it.
Code:

```matrix_member return_address(int i,int j,matrix_member m,int size) {     int a;   matrix_member tmp = m;     for(a=0;a<(i*size+j);a++);         tmp++;         return tmp; }```
• 11-07-2002
condorx
i tried it it doesnt the solution
i changed return adress but i have the same problem???
• 11-07-2002
condorx
thanks this works
thanks:)))