我很难将双指针的引用传递给函数。我有这个:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_ROWS 2
#define MAX_COLS 2
int main(void){
int i=0,lenght=0,maxColumns=0,j=0,k=0,maxRows=0,maxColumns2=0;
int **columnVect;
/*lengthOfPtr gives me the columns that i need. */
if((lenght=(lengthOfPtr(ptrMessage)))<=3){
maxColumns=1;
maxColumns2=2;
}else{
maxColumns=lenght/2;
maxColumns2=maxColumns;
}
/* Allocating Memory for the double pointer. */
columnVect=malloc(maxColumns2 * sizeof(int*));
if(columnVect == NULL){
fprintf(stderr, "Memory error.\n");
exit(0);
}
for(i = 0; i < maxColumns2; i++){
columnVect[i] = malloc(maxRows * sizeof(int));
if(columnVect[i] == NULL){
fprintf(stderr, "Memory error.\n");
exit(0);
}
}
// Do something that fills columnVect[i][j]
/* Passing the double pointer to messageVector */
messageVector(&columnVect,maxColumns);
return 0;
}
int messageVector(int ***columnVect,int maxColumns){
/* Allocating Memory for the triple pointer. */
columnVect=(int ***)malloc(sizeof(int **));
//Do something here . . .
return messageVector;
}
如果我运行程序给我:(lldb)
在:
3 启动 libdyld.dylib`start: 0x7fff88b447e0: nop
任何人都可以告诉我如何以正确的方式做到这一点?谢谢!