Ir para conteúdo
Fórum Script Brasil

Nathan D Souza

Membros
  • Total de itens

    5
  • Registro em

  • Última visita

Posts postados por Nathan D Souza

  1. O Erro e o seguinte eu não consiguo atribuir 1 valor a 1 struct:

    Referencia->Ind = X->Ind;//O Ind e igual a Index.
    cout<<Referencia->Ind<<endl;

    E o Index da referencia da 1 numero estranho e aleatorio,detalhe normalmente os numeros são: 0,01,Numero Aleatorio,NumeroAleatorio

    o codigo completo esta aqui:

    #include <iostream>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    
    using namespace std;
    
    int IndexTotal = 0;
    
    struct ItemList
    {
    int Ind = IndexTotal;//Index
    ItemList* Prox;//Proximo
    ItemList* Ante;//Anterior;
    bool Cripto;//Criptografada ou não
    char Data[];//Valor
    };
    
    ItemList* Referencia = (ItemList*) malloc(sizeof(ItemList));;//Usado para eu encontrar outros valores
    
    //Metodos da Lista
    
    void NewItem(char Data[],bool Data02);//Criado 1 novo item a lista
    
    ItemList* GetList(int x);
    
    
    int  main()
    {
    
            NewItem("Nathan",false);
    
            NewItem("\nKevin",false);
    
            NewItem("\nBruno",false);
    
    
           ItemList* Temp;
    
           int x = 1;
           while(x <= IndexTotal)
           {
                 Temp = Referencia;
                 Referencia = Referencia->Prox;
              //   free(Temp);
                 Temp = NULL;
                 x++;
           }
           IndexTotal = 0;
    
           return 0;
    }
    
    
    void NewItem(char Data1[],bool Data02)
    {
            ItemList* X = (ItemList*) malloc(sizeof(ItemList) + strlen(Data1));
    
             for(int x = 0;x < strlen(Data1);x++)
             {
                    X->Data[x] = Data1[x];
             }
    
             X->Cripto = Data02;
             X->Ind = IndexTotal;
    
    
             if(IndexTotal == 0)//Caso seja o primeiro não vai ter Antes
             {
                 X->Ante = 0;
             }
    
             else// Caso não seja o primeiro
              {
                    X->Ante = Referencia;
              }
    
    
             Referencia = X;
             Referencia->Ind = X->Ind;
             cout<<Referencia->Ind<<endl;
    
             for(int x = 0;x < IndexTotal;x++)
             {
                    ItemList * Temp = (ItemList*) malloc(sizeof(ItemList));//Variavel auxilar da Referencia
    
                    Temp = Referencia;
    
                    if(Referencia->Ind == IndexTotal)//Caso seja o ultimo
                    {
                        Referencia->Prox = NULL;
                    }
    
    
                    else
    
                    Referencia = Referencia->Ante;
                    Referencia->Prox = Temp;
                    free(Temp);
                    Temp = NULL;
    
    
             }
             Referencia = X;
             cout<<Referencia->Ind;
             IndexTotal++;
    }
    
  2. Bom, eu estou aprendendo C++, mas eu estou tendo dificuldades(muita) em aprender alocação dinamica, então eu quero escrever o que eu entendi e também algumas duvidas minhas.Ai vocês respondem a duvida e me corrijam se eu escrever algo errado

    O Objetivo da alocação dinamica é apenas um: economizar mémoria.Porem na função malloc eu não especifico o numero de Bytes que eu vou usar eu so escrevo o tipo de variavel ou seja porque eu não uso 1 variavel comum, qual é a diferença:

    int *nome = (int *) malloc(sizeof(INT)); // 4 Bytes

    int nome; // 4 Bytes

    Outra duvida que não tem nada a ver com alocação dinamica. Pode misturar c com c++ ?

×
×
  • Criar Novo...