私は、私のCプログラム内の関数から返す、playerInformation
という構造体を持っています。以下の関数は、私が書いた関数です。Cの関数からポインタを返すには?
これは適切な構造体を検出し、printf
を使用して関数内の詳細を出力できます。しかし、私は主関数内の情報を印刷できるようにポインタを返すことができないようです。私はこの警告を取得し、このコードで
:
MainTest.c: In function ‘main’:
MainTest.c:34: warning: assignment makes pointer from integer without a cast
MainTest.c(ライン33および34)
struct playerInformation *test;
test = findPlayerInformation(head, 2);
StructFucntions.c
struct playerInformation *findPlayerInformation(struct playerInformation *head, int playerIndex) {
struct playerInformation *ptr;
for(ptr = head; ptr != NULL; ptr = ptr->next) {
if(ptr->playerIndex == playerIndex) {
return ptr;
}
}
return NULL;
}
findPlayerInformation'は(main'定義 '前maintest.cに含まれ、ヘッダファイルに入れて)宣言'のですか? – purplepsycho
プロトタイプを使用前に入れてください。 – BLUEPIXY
実際には、これは "ちょうど"の警告です。findPlayerInformationはメイン関数の下にありますか、または関数プロトタイプを前に定義しましたか? – jboockmann