我有一个结构称为playerInformation
,我想从我的函数C程序中返回,下面的功能是我写的一个。如何从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