I tried to print a matrix for home work in a transpose type of way but without pronting the first element of each array (printing place [1] and forward...).
but when i rint it the output shows me that at at the end of every col theres another number thats not suppose to be there (chatgpt says its "garbage") so can someone please help me fix my program in any way cuz i tried for 2 hours and havent figiured it out yet.
-btw one of the things i cant use is indexs in loops and such like int i/j so i have to use only pointers.
#include <stdio.h>
void transpose(int **arr){
int lenrows = 0;
int **temp = arr;
while(*temp != NULL){
lenrows = lenrows + 1; //ספרתי את שורות הפויינטר ALL
temp = temp + 1;
}
int maxCol = 0; //לספירת העמודות
int **rc = arr;//fst pointer
while (*rc != NULL) {
int *colpointer = *rc; // מצביע לתחילת השורה
int cur = *colpointer; // הערך הראשון מציין את האורך של השורה
if (cur > maxCol){
maxCol = cur;
}
rc++;
}
int col = 0;
while(col < maxCol){
int **row = arr;
while(*row != NULL){
int *currow = *row;
int size = *currow;
if (col < size) {
printf("%-6d", *(currow + col + 1));
}else{
printf(" ");
}
row = row +1;
}
printf("\n");
col = col +1;
}
}
int main(){
int A[]={5,-5,14,5,2};
int B[]={3,6,11};
int C[]={4,1,-3,4};
int D[]={6,2,7,1,8,2};
int E[]={2,15};
int F[]={3,4,-2};
int *All[]={A,B,C,D,E,F,NULL};//מערך מצביעים למערכים שבהם יש מספרים
printf("transpose answer: \n");
transpose(All);
}
(i added the og qustion if annyone wanna read)