如何在c中访问函数中的指针数组
我有一个指针数组,然后我尝试访问函数中指针数组的值,但它崩溃了。 为什么以及如何访问这些值如何在c中访问函数中的指针数组,c,C,我有一个指针数组,然后我尝试访问函数中指针数组的值,但它崩溃了。 为什么以及如何访问这些值 char* test[3][1024]={"Trans1","Trans2","Trans3"}; creerBlock(test,3, NULL,1); extern BLOCK* creerBlock(char* transactions[], int nbTransactions, char *pHashCodePrec, int numBloc) 我试过: printf("%s", *trans
char* test[3][1024]={"Trans1","Trans2","Trans3"};
creerBlock(test,3, NULL,1);
extern BLOCK* creerBlock(char* transactions[], int nbTransactions, char *pHashCodePrec, int numBloc)
我试过:
printf("%s", *transactions[0]);
以及:
printf("%s", transactions[0]);
你应该使用
printf("%s", *transactions);
对于第一个元素
及
对于第二个元素。
因为trasactions有一个类型char*,因为char*可以是数组,所以通过编写char*test[3][1024],您就创建了一个三维数组。您应该在char*test[3]和char test[3][1024]之间进行选择
然后您可以使用:
printf("%s", transactions[0]);
您的编译器不是已经在第一行发出警告了吗?欢迎使用SO。请打开编译器中的所有警告。对于GCC使用-Wall和-Wextra。如果您收到警告,请仔细阅读。char*test[3][1024]->char*test[3]。然后打印%s,事务[0];。如果有其他类型,请尝试更改%s(如果在其他contexte中使用)
printf("%s", transactions[0]);