我不明白为什么下面的代码会返回一个指针 0x1。stock 节点很好,如以下输出所示:
ticket_name passed comparison.
ticket_type passed comparison.
ticket_zone passed comparison.
但是返回的指针是 0x1,我试图将该指针与链表中的指针进行比较以删除一个节点,这显然是失败的。编译该函数时也会出现警告:
tm_options.c:85: warning: assignment makes pointer from integer without a cast
tm_options.c:190: warning: assignment makes pointer from integer without a cast
据我所知,这个警告是因为函数缺少函数原型,而没有原型的函数的默认返回类型是 int。但我在 tm_utility.h 中有一个函数原型
编辑:这是我的 Makefile 的 pastebin 以防万一这与它有关 http://pastebin.com/UFw9B4Hd
struct stock_node * find_ticket(tm_type_ptr tm, char *, char, char *);
以下是返回错误值的函数:
struct stock_node * find_ticket(tm_type * tm, char * ticketName, char ticketType, char * ticketZone) {
struct stock_node * curr;
BOOLEAN found = FALSE;
curr = tm->stock->head_stock;
while (curr != NULL && found == FALSE) {
printf("curr: %p\n", (void *) curr);
printf("curr->ticket_name: %s\n", curr->data->ticket_name);
printf("curr->ticket_type: %c\n", curr->data->ticket_type);
printf("curr->ticket_zone: %s\n", curr->data->ticket_zone);
if (strncmp((char *)curr->data->ticket_name, ticketName, TICKET_NAME_LEN + 1) == 0) {
printf("ticket_name passed comparison.\n");
if ((char) curr->data->ticket_type == ticketType) {
printf("ticket_type passed comparison.\n");
if (strncmp((char *)curr->data->ticket_zone, ticketZone, TICKET_ZONE_LEN + 1) == 0) {
printf("ticket_zone passed comparison\n");
found = TRUE;
return curr;
}
}
} else {
curr = curr->next_node;
}
}
return NULL;
}
任何帮助将不胜感激。如果您需要更多信息,请不要犹豫问我。
调用代码是:
struct stock_node * stockNode;
((stockNode = find_ticket(tm, ticketName, ticketType, ticketZone) != NULL))
根据要求: struct stock_node 定义:
typedef struct stock_node
{
struct stock_data * data;
struct stock_node * next_node;
} stock_node;
此外,tm_type_ptr:
typedef struct tm * tm_type_ptr;