Je code suivant cppComment utiliser realloc dans cpp
#include <stdio.h> /*utiliser printf*/
#include <fcntl.h>
#include <math.h> /*utiliser pour les formules de math*/
#include <malloc.h>
#include <iostream.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
/* Le type nombre complexe */
typedef struct {
double Preel;
double Pimaginaire;
} COMPLEXE;
#define ALLOC_ERROR 1
void indienne(double *MatE, int tE, int nE, double *SortieExp, double *Tempbis)
{
double *TempE=NULL, *SortieE=NULL;
int *dec=NULL;
int i, tampon, kE;
kE=(int)(log(nE)/log(2));
if(nE==8)
kE=3;
/* ALLOCATION DES MATRICES*/
if (!(TempE = (double *)calloc(tE * tE, sizeof(double))))
exit(ALLOC_ERROR);
printf("check1 te=%d, nE=%d",tE,nE);
if (!(dec = (int *)realloc(kE , sizeof(int))))
exit(ALLOC_ERROR);
if (!(SortieE = (double *)calloc(tE * tE, sizeof(double))))
exit(ALLOC_ERROR);
printf("check2 te=%d",tE);
memcpy(TempE,MatE,tE * tE * sizeof(double));
for (i=0; i<tE; i++)
*(Tempbis+(tE * i) + i) = 1.0;
if (nE==1)
{
memcpy(SortieExp, MatE, tE*tE*sizeof(double));
}
else
{
printf("kE=%d, nE=%d\n", kE, nE);
if (nE%2==0)
decompose(kE, nE,dec);
else
decompose(kE, nE-1, dec);
for (i=0; i<kE; i++)
{
carre(TempE, tE, SortieE);
memcpy(TempE, SortieE, tE*tE*sizeof(double));
tampon=*(dec+i);
if (tampon==1)
{
mult(Tempbis, tE, tE, SortieE, tE, tE, SortieExp);
memcpy(Tempbis, SortieExp, tE*tE*sizeof(double));
}
}
if (nE%2 !=0)
{
memcpy(Tempbis, SortieExp, tE*tE*sizeof(double));
mult(Tempbis, tE, tE, MatE, tE, tE, SortieExp);
}
}
free(TempE);
free(SortieE);
free(dec);
}
Lorsque je compile le code suivant occurres d'erreur
conversion non valide de 'int' à 'void *' [-fpermissive] |
qui est sur le point suivant ligne de code
if (!(dec = (int *)realloc(kE , sizeof(int))))
Comment puis-je supprimer cette erreur?
La fonction 'realloc()' ne peut s'appliquer qu'à un tableau encore alloué avec la fonction 'malloc() 'ou' calloc() '. La variable 'kE' est un entier alloué sur la pile. –