为什么感觉代码没问题,但报出来一堆语法错误,有大佬看看吗

呱呱683 2024-10-31 17:05:30
//头文件
#include "mod.h"
#include <stdlib.h>
typedef char ElementType;
typedef struct BinTree {
	ElementType data;
	BinTree* rchild;
	BinTree* lchild;
}BinTree;

BinTree* creatTree();//建立二叉树
void postTree(BinTree* tree);//遍历二叉树(先序)

//函数文件
//#include "mod.h"
//#include <stdlib.h>
BinTree* creatTree() {
	BinTree* binTree;
	char c = getchar();
	if (c == '#') {
		return NULL;
	}
	binTree = (BinTree*)malloc(sizeof(BinTree));
	binTree->data = c;
	binTree->lchild=creatTree();
	binTree->rchild = creatTree();
	return binTree;
}

void postTree(BinTree* tree) {
	if (tree == NULL) {
		return;
	}
	printf("%s	",tree->data);
	postTree(tree->lchild);
	postTree(tree->rchild);
	return;
}

//主文件
//#include "mod.h"
//#include <stdio.h>
int main(){
	BinTree* a ;
	a = creatTree();
	postTree(a);
	return 0;
}

 

...全文
305 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
forever74 2024-11-01
  • 打赏
  • 举报
回复

报语法错误就把报错截图完整贴上来,这样肯于为你解决问题的人看一眼就行,免得还得动手编译,挺麻烦的,有劝退效应。

  • 打赏
  • 举报
回复
#include <stdio.h>
// ...
    printf("%c", tree->data);

70,020

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧