Jump to content

Preenchimento de uma String em C através de uma função


Recommended Posts

Posted

Meu problema é o seguinte: Quero preencher esse array(String) com os nós da arvore, montando uma estrutura específica. O código até compila mas trava e não mostra o resultado.

 

char *saida(no *arvore, char resultado[]){
    
    String aux;
    
    char Ap[2] = "(";
    char Fp[2] = ")";
    
    strcat(resultado,Ap);
    
    sprintf(aux, "%i", arvore->chave);
    
    strcat(resultado,aux);
    
    sprintf(aux, "%i", arvore->cor);
    
    strcat(resultado,aux);
    
    if(arvore->esq == NULL){
        
        if(arvore->dir != NULL){
            
            strcat(resultado,Ap);
            strcat(resultado,"X");
        
        }else{
            
            strcat(resultado,Ap);
            strcat(resultado,"X");
            strcat(resultado,Fp);
        }
        
    }else{
        
        strcat(resultado,saida(arvore->esq,resultado));    
        
        }
     
    if(arvore->dir == NULL){
        
        if(arvore->esq != NULL){
            
            strcat(resultado,"X");
            strcat(resultado,Fp);
        
        }else{
            
            strcat(resultado,Ap);
            strcat(resultado,"X");
            strcat(resultado,Fp);
        }
        
    }else{
        
        strcat(resultado,saida(arvore->esq,resultado));
    }
    
    if(arvore->dir == NULL){
        
        if(arvore->esq != NULL){
            
            strcat(resultado,"X");
            strcat(resultado,Fp);
        
        }else{
            
            strcat(resultado,Ap);
            strcat(resultado,"X");
            strcat(resultado,Fp);
        }
    }else{
        
        strcat(resultado,saida(arvore->dir,resultado));    
    }
    
    strcat(resultado,Fp);
        
    return resultado;
}
Posted

vamos ver se consegues descobrir o teu problema em concreto por meias palavras:

se eu apresentar o seguinte código, consegues visualizar algum problema ?

#include <stdio.h>

int main(int argc, char ** argv) {
    int size_of_string = 2;

    for (int i = 0; i < size_of_string; i++) {
        size_of_string = size_of_string + 1;
    }

    return 0;
}
IRC : sim, é algo que ainda existe >> #p@p

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.