Ir ao conteúdo
  • Cadastre-se

Erro: Stack corrupted


andrepinz

Posts recomendados

Bom dia ... estou com o seguinte código apresentando o erro "Run-Times Check Failure #2 - stack around the variable 'aux_linha' was corrupted" ao sair do método...

Estou usando o visual studio 2012 em modo debug...

Obrigado!


void arquivo_test(int i_linha)
{
FILE *fptr, *arq_novo, *arq_saida;
int i, j, k, conta_virgula, gravou;
char linha[10000], nome_arquivo[100], novo_test[50000];
char aux_linha[maxvar+1][100];
//char **aux_linha;

//aux_linha = (char **) malloc (sizeof(char));

//ABRE ARQUIVO .test conforme a geração da população
strcpy_s(nome_arquivo,"C:\\Viviane\\Dados\\");
strcat(nome_arquivo, nome_bases[opcao]);


if (cont_part == 0)
strcat(nome_arquivo,"0");

if (cont_part == 1)
strcat(nome_arquivo,"1");

strcat(nome_arquivo,".txt");

//strcat(nome_arquivo,".data");
fptr=fopen(nome_arquivo,"r");

if(fptr==NULL)
{
printf("Nao posso abrir o arquivo %s para r. Funcao arquivo_test",nome_arquivo);
getchar();
exit(1);
}
conta_virgula = gravou = 0;
//printf("teste monta base");

//se o arquivo nova test já existir é inicializado
strcpy_s(novo_test,nome_bases[opcao]);
strcat(novo_test, ".test");
if((arq_saida=fopen(novo_test,"w"))==NULL)
{
printf("\nO arquivo nao pode ser aberto...%s para w. Funcao arquivo_test", novo_test);
getchar();
exit(1);
}
fclose(arq_saida);//fecha o arquivo de test

int reccount = 0;
while(fgets(linha,10000, fptr ) != NULL)
{
//linha = (char*) realloc( linha, (reccount+1) * strlen(linha));
//le a linha com os valores dos atributos
//fgets(linha, 1000, fptr );
i = j = 0;
conta_virgula = gravou = 0;
//separa os valores encontrados na linha lida
//em um vetor
while (linha[i] != ',' && linha [i] != '\0' && linha[i] != '\n')
{
// usar este while para separar os valores dos atributos em um vetor e conforme
// seu vcalor em popVar[i][j] gravar no novo arquivo ou nao
// ser for maior que 0.5 grava no arquivo
/*
printf("\n%s", linha[i]);
aux_linha[conta_virgula] = (char *) malloc (sizeof(char));
aux_linha[conta_virgula][0] = '\0';
aux_linha[conta_virgula] = (char *) realloc(aux_linha[conta_virgula], sizeof(char) * (strlen(aux_linha[conta_virgula] ) + strlen ( linha ) + 1 ));
aux_linha[conta_virgula][strlen(aux_linha[conta_virgula]) + strlen(linha)] = '\0';
for(int c = 0; c < strlen(linha); c++){
aux_linha[conta_virgula][c] = linha[c];
}
*/
aux_linha[conta_virgula][j] = linha[i];

if (linha[i+1] == ',' || linha [i+1] == '\0')
{
aux_linha[conta_virgula][j+1] = '\0';
i = i + 2;
conta_virgula = conta_virgula + 1;
j = 0;
}
else
{
i = i + 1;
j = j + 1;
}
printf("");
}
reccount++;
aux_linha[conta_virgula][j] = '\0';
//após separar num vetor identifica o que será gravado no novo arquivo
// base de dados para executar o c45

strcpy_s(novo_test, "C:\\Viviane\\Dados\\");
strcpy_s(novo_test,nome_bases[opcao]);
strcat_s(novo_test, ".test");

if ((arq_novo=fopen(novo_test,"a+"))!=NULL)
{
for(k = 0; k < maxvar; k++)
{
if (popVar[i_linha][k] > 0.5 )
{
if (k!= 0 && gravou == 1)
fprintf_s(arq_novo,",");
fprintf_s(arq_novo,"%s",aux_linha[k]);
gravou = 1;
}


}
if (gravou == 1)
fprintf_s(arq_novo,",");
fprintf_s(arq_novo,"%s",aux_linha[maxvar]);
}
fprintf_s(arq_novo,"\n");
fclose(arq_novo);
}

fclose(fptr);
}

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...