4
I have the following code on C, for a wide search:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
//Variáveis globais
int id = 0;
int proximo = 0;
//Função de Busca em Largura
int buscaLargura(int *grafo, int alvo, int inicio, int tamanho)
{
    struct str_no fila[tamanho];
    int indice = 0;
    int achou = 0;
    //Procura nó inicial
    while(achou == 0)
    {
        if(grafo->id == inicio)
        {
            achou = 1;
        }
        else
        {
            grafo = grafo->proximo;
        }
    }
    achou = 0;
}
//Procura o nó alvo
fila[indice] = grafo;
indice++;
while(indice > 0 && achou == 0)
{
    if(grafo->id == alvo)
    {
        achou = 1;
    }
    else
    {
        while(grafo->proximo != NULL)
        {
            grafo = grafo->proximo;
            fila[indice] = grafo;
            indice++;
        }
        //Desenfileira
        grafo = pilha[0];
        for(int i = 1; i < indice; i++)
        {
            pilha[i-1] = pilha[i];
        }
        indice--;
    }
    return(grafo);
}
Whenever I try to run, the compiler "Codeblocks" returns the following ERROR:
||=== Build file: "no target" in "no project" (Compiler: Unknown) ===| In Function 'buscaLargura':| |17|error: array type has incomplete element type| |24|error: request for Member 'id' in Something not a Structure or Union| |30|error: request for Member 'next' in Something not a Structure or Union| |error: 'Indice' undeclared here (not in a Function)| | 37|Warning: data Definition has no type or Storage class| |37|error: 'graph' undeclared here (not in a Function)| |38|error: expected '=', ',', ';', 'asm' or 'attribute' before '++' token| |39|error: expected Identifier or '(' before 'while'| ||=== Build failed: 7 error(s), 1 Warning(s) (0 minute(s), 0 Second(s)) ===|
Thank you very much, I am doing this, tirelessly studying this programming language, your tips and explanations have served me very
– user43328
On static array with dynamic value, actually you can. Maybe it’s not C89, but C99 already is. And it’s considered static allocation
– Jefferson Quesado