#include<stdio.h>
#include<stdlib.h>
int **transpose(int a[], int b[], int raw, int column){
int i, j;
for(i=0; i < raw ; i++)
for(j=0; j < column ; j++)
*(b+(j*raw + i)) = *(a+(i*column + j));
return *b;
}
int **mk_matrix(int raw, int col){
int i;
int **matrix = (int**)malloc(sizeof(int*)*raw);
matrix[0] = (int*)malloc(sizeof(int)*(raw*col));
for(i=1 ; i < raw ; i++)
matrix[i] = matrix[i-1] + col;
return matrix;
}
void main(void){
int r, c, i, j;
printf("Input the size of matrix : ");
scanf("%d %d", &r, &c);
int **matrix = mk_matrix(r, c);
int **trans_matrix = mk_matrix(c, r);
printf("Input elements of the %dx%d matrix : ", r, c);
for(i=0; i < r ; i++)
for(j=0; j < c ; j++)
scanf("%d", &matrix[i][j]);
**trans_matrix = transpose(matrix[0], trans_matrix[0], r, c);
for(i=0; i < c ; i++){
for(j=0; j < r ; j++)
printf("%d ", trans_matrix[i][j]);
printf("\n");
}
}
In dev c++, this code runs correctly by I wanted but it comes
- return makes pointer from integer without a cast -> return *b;
- assignment makes integer from pointer without a cast -> **trans_matrix = transpose(matrix[0], trans_matrix[0], r, c); warnings.
How can i fix my code not showing warnings?
bis already a pointer toint. C11 Standard - 6.3.2.1 Other Operands - Lvalues, arrays, and function designators(p3) so attempting to return*battempts to return typeint.gcc, at a minimum use:-Wall -Wextra -Wconversion -pedantic -std=gnu11) Note: other compilers use different options to produce the same results. Passing the OPs code through the compiler results in 4 major warnings. You need to fix those warnings, As it is, the results of the compile is NOT what you want.void main(void){per the C standard, there are only 2 valid signatures formain(). They are:int main( void )andint main( int argc, char *argv[])