Originally Posted by
cnewbie1
scout: That works with a void method, as mentioned further up. But with a char method, receiving and returning a multi-dimensional array, I cannot get it to work that way. Using a typedef, however, worked beautifully.
mstring2 takes a multidimensional array and returns the same multidimensional array address (the mstr2 becomes a single array though). just play with it and hopefully it'll help. . yeah the typedef solution is sweet.
Code:
#include <stdio.h>
#include <stdlib.h>
char *mstring2(char *);
int main(void)
{
char mbuf[5][10];
char *mstr2 = mstring2(*mbuf); // takes a multidimensional array and returns multidimensional array (address)
printf("%p\n", mstr2); // check if equal
printf("%p\n", &mbuf[0][0]); //
printf("this should be 49 = %d\n",mbuf[4][9]);
printf("this should be 1 = %d\n",mbuf[0][1]);
char k = 'k';
char p = 'p';
*(mstr2+(4*10)+9) = 3;
*(mstr2+(0*10)+1) = k;
*(mstr2+(1*10)+1) = p;
printf("this should be 3 = %d\n",mstr2[49]);
printf("this should be 3 = %d\n",mbuf[4][9]);
printf("this should be k = %c\n",mbuf[0][1]);
printf("this should be p = %c\n",mbuf[1][1]);
getchar();
return 0;
}
char *mstring2(char *k) {
for (int i=0;i<50; i++)
{
*(k+i) = i;
}
return k;
}