[問題] 請問該如何把二維陣列回傳主程式??

看板C_and_CPP作者 (我的雞巴女友)時間6年前 (2018/06/08 06:41), 編輯推噓-1(128)
留言11則, 8人參與, 6年前最新討論串1/1
請問各位強者 在int **getrandomCX() 這個函式裡面 我該如何把二維陣列回傳到主程式???? #include <stdio.h> #include <stdio.h> #include <stdlib.h> #include <time.h> #include <malloc.h> int *getrandom(); int **getrandomCX(); int main(int argc, char **argv) { int *p; int **T; p=getrandom(); for(int i=0;i<10;i++) { printf("*(p+%d) : %d\n",i,*(p+i)); } T=**getrandomCX(); for(int i=0;i<10;i++) { for(int x=0;x<5;x++) { printf("===i=%d x=%d ==>=%d\n",i,x, *(*(T+i)+x)); } } return 0; } int *getrandom() { static int r[10]; srand((unsigned)time(NULL)); for(int i=0;i<10;i++) { r[i]=rand()%100+1; //printf("r[%d]=%d\n",i,r[i]); } return r; } int **getrandomCX() { static int rx[10][5]; srand((unsigned)time(NULL)); for(int i=0;i<10;i++) { for(int x=0;x<5;x++) { rx[i][x]=100; // printf("r[%d]=%d\n",i,rx[i][x]); } } return *rx; } -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.228.242.36 ※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1528411285.A.8A1.html

06/08 07:22, 6年前 , 1F
伸手牌伸好伸滿?
06/08 07:22, 1F

06/08 11:36, 6年前 , 2F
好想推伸一次不夠你有沒有伸兩次, 可是他真的伸兩次
06/08 11:36, 2F

06/08 23:35, 6年前 , 3F
T=getrandomCX();
06/08 23:35, 3F

06/08 23:41, 6年前 , 4F
先弄懂double point跟二維陣列的差別
06/08 23:41, 4F

06/08 23:57, 6年前 , 5F
https://ideone.com/zJLLnK 不知道是不是你所想的
06/08 23:57, 5F

06/09 00:55, 6年前 , 6F
傳不出來有沒有想過傳進去
06/09 00:55, 6F

06/09 03:49, 6年前 , 7F
手動置底?
06/09 03:49, 7F

06/09 14:46, 6年前 , 8F
你該問的是為什麼你傳不出去...
06/09 14:46, 8F

06/09 14:47, 6年前 , 9F
給你些關鍵字 stack, heap, local vaiable
06/09 14:47, 9F

06/10 11:50, 6年前 , 10F
包含前一篇應該有違反版規2
06/10 11:50, 10F

06/10 22:45, 6年前 , 11F
int ** 不等於二維陣列,不要隨便亂code
06/10 22:45, 11F
文章代碼(AID): #1R6RILYX (C_and_CPP)