-5
#include<stdlib.h>
#include<stdio.h>
struct tree{char info;struct tree *left;struct tree *right;};
struct tree *root;
struct tree *stree(struct tree *root,struct tree *r,char info);
void print_tree(struct tree *root,int l);
int main(void)
{
char s[80];
root=NULL;
do {
printf("enter a letter:");
gets(s);
root=stree(root,root, *s);
}
while(*s); // <- ???
print_tree(root,0);
return 0;
}
struct tree *stree(struct tree *root,struct tree *r,char info;{ // <- ???
if(!r) {
r=(struct tree *) malloc(sizeof(struct tree));
if(!r) {
printf("out of memory \n");
exit(0);
}
r->left=NULL;
r->right=NULL;
r->info=info;
if(!root)
return r;
if(info<root->info)
root->left=r;
else
root->right=r;
return r;}if(info<r->info)stree(r,r->left,info);else
stree(r,r->right,info);return root;}
void print_tree(struct tree *r,int l);
{
int i;
if(!r) return ;
print_tree(r->right,l+1);
for(i=0;i<l;++i)
printf(" ");
printf("%c \n",r->info);
print_tree(r->left,l+1);
}
さて、デバッガでコードをステップ実行しましたか?それが最初のことです。プログラムのデバッグ方法を学ぶことは、言語を学ぶことと同じくらい重要です。また、読みやすいようにコードを適切にインデントしてください。 – OldProgrammer
Q:どのコンパイラとどのデバッガを使用していますか? * FIRST *を試してみるには、デバッガを1行ずつステップ実行して、 "すべてがOK"になっていることを確認してください。 – paulsm4
インデントが... –