【发布时间】:2015-11-26 15:18:05
【问题描述】:
这是我的第一个 C 程序,我不知道为什么会出现以下错误。
#include <stdio.h>
#include <stdlib.h>
typedef struct {
struct ListNode* next;
int content;
} ListNode;
int main() {
//puts("Hello UPC World"); /* prints Hello UPC World */
//ListNode* h = malloc(sizeof(ListNode));
gridinit(3, 5);
//int c = h->content;
//printf("%d",c);
return EXIT_SUCCESS;
}
ListNode* gridinit(int numcolumns, int numrows) {
ListNode* head = malloc(sizeof(ListNode));
head->content = 2;
head->next = NULL;
return head;
}
为什么我会收到错误提示
func gridinit() 中的类型冲突
【问题讨论】:
-
您正在从函数返回一个节点,但为什么不将其分配给调用 gridinit 的变量。
-
看来你需要前向声明在主函数前添加这一行:
ListNode *gridinit( int numcolumns, int numrows ); -
请缩进你的代码
标签: c function implicit-declaration