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++;
}
Pergunta
Nathan D Souza
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++; }Editado por Nathan D SouzaLink para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.