The problem is the following: Have to check if the words in the matrix are palindromes or not. Have to read the words as well. My main problem is introducing the words because until now I could only do a function reading the first letter, not the whole word. After that, I think that I can check alone if it is a palindrome or not. This is an example of data:
mat←["ac" "lup" ]
["ou" "lupul"]
["ABBA" "greu" ]
m←3 number of rows
n←2 number of columns
This what I wrote until now: A function where you introduce the words:
char** read(int *m ,int *n)
{
printf("No of lines=");
scanf("%d",m);
printf("No of columns=");
scanf("%d",n);
char **a=(char**)malloc(*m*sizeof(char*));
for (int i=0;i<*m;i++)
{
a[i]=(char*)malloc(*n*sizeof(char));
for (int j=0; j<*n; j++)
{
fflush(stdin);
printf("Element [%d][%d]=",i,j);
gets(a[i]+j); // <=> &a[i][j]
}
}
return a;
}
Another one which displays it:
void display(char **x, int m, int n)
{
for (int i=0; i<m; i++)
{
for (int j=0; j<n; j++)
printf("%c ",x[i][j]);
printf("\n");
}
}
Another one which deletes the data:
void freematrix(char **x, int m)
{
for (int i=0; i<m; i++)
free(x[i]);
free(x);
}
This is the main part:
int main()
{
int m, n;
char **mat;
mat=read(&m,&n);
display(mat,m,n);
freematrix(mat,m);
return 0;
}