Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does it say I don't declare a varibale but actually I declared?

It’s about Bitree.
It should output Postorder traversal after input Preorder traversal and Inorder traversal.

#include <stdio.h>
#include <string.h>

void traverBitree(char *first, char *middle);
int index = 0;

int main(void)
{
    char first[27], middle[27]; 
    gets(first);
    gets(middle);
    traverBitree(first, middle);
}

void traverBitree(char *first, char *middle)
{
    if (strlen(middle) == 0)
        return;                 
    char ch = first[index++];   
    int pos = 0;                
    while (middle[pos++] != ch) 
    char left[26], right[26];   
    strncpy(left, middle, pos); 
    strcpy(right, middle+pos);  
    right[pos+1] = '\0';        
    traverBitree(first, left);  
    traverBitree(first, right);
    printf("%c", ch);     
}

I think I have declared the "left" and "right", why actually not?
There must be something wrong but I don’t know.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your while statement while (middle[pos++] != ch) lacks braces, so the compiler is looking for them and the code below won’t compile well.

You have to wrap the statements you want in {}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading