Here is the code, which fills an array with input numbers and outputs it. All these previous functions are executed with pointers, but the last function, which is supposed to print the numbers in a certain row, has some kind of a bug. It doesn't print the last row of the array, since array become 3x3 sort. What is the problem and how could I fix it? And what can you say about code itself. Is it flex, maintainable and useful or vice versa?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int** MAC_ROS(int str,int col);
int* task(int strm,int colm);
int* getNumber(int *p,int colm);
void GET_NUMBER(int *pointer,int col,int rowDestination);
void OUT(int *p,int str,int col);
int *point=NULL;
int arr[20][20];
int main(void){
int col,str,rowDestination;
printf("Input columns="); scanf("%d",&col);
printf("Input strings="); scanf("%d",&str);
point=task(str,col);
printf("rowDestination="); scanf("%d",&rowDestination);
GET_NUMBER(point,col,rowDestination);
}
int* task(int strm,int colm)
{
int *MAS_POINT;
MAS_POINT=(int*)MAC_ROS(strm,colm);
OUT(MAS_POINT,strm,colm);
return MAS_POINT;
}
int** MAC_ROS(int str,int col)
{
int a=0;
int *point,**el;
point=(int*)malloc(col*str*sizeof(int));
el=(int**)point;
for(int i=0;i<str;i++)
{
point=point+str*i;
for(int j=0;j<col;j++)
{
scanf("%d",&a);
*(point+j)=a;
}
}
return el;
}
void OUT(int *p,int str,int col)
{
for(int i=0;i<str;i++)
{
p=p+str*i;
for(int j=0;j<col;j++)
{
printf("%d ",*(p+j));
}
printf("\n");
}
}
void GET_NUMBER(int *pointer,int col,int rowDestination)
{
pointer=pointer+((rowDestination-1)*col);
for(int t=0;t<col;t++)
{
printf("%d ",*(pointer+t));
}
}
MAS_POINTorGET_NUMBERare certainly allowed in C, but they're seldom used for variables or functions. The names normally indicate a constant or macro, either via#defineorenumor similar constructs. There are a few examples where it is used for a type name (FILE *being the best known; in POSIX contexts,DIR *is another example). Generally, other people will find your code easier to read if you reserve all upper-case names for constants or macros.getNumber()but you don't define or use it. You should remove its declaration. It's odd thattaskis in lower-case but the other defined functions are in upper-case.