如何在domaine中從domain_cx中檢索數據,一旦我在函數get_domaine(...)中嘗試了以下操作,但結果不是預期的結果(0-2而不是0-2 3)。這裏是我的代碼char *轉換爲char *
#include <stdio.h>
#include <stdlib.h>
int get_domaine(char * domaine)
{
char (*ptr_dom)[10];
ptr_dom = (char (*)[10]) domaine;
printf("%s ", ptr_dom[0]); // will print
printf("%s ", ptr_dom[1]); // will not print even thought there is data.
return 1;
}
int main(int argc,char * argv[])
{
char *domaine_cx[10];
domaine_cx[0] = "0-2";
domaine_cx[1] = "3";
if(get_domaine((char *)*domaine_cx)) printf("Ok");
return EXIT_SUCCESS;
}
我編輯它,它現在編譯。 – maximegir