error: incompatible types when assigning to type ‘double’ from type ‘void *’
Bonjour,
voila j'ai un probleme de compilation que je ne comprends pas .
donc voici mes erreurs :
Citation:
main.c: In function ‘main’:
main.c:19: error: void value not ignored as it ought to be
detruire.c: In function ‘detruire’:
detruire.c:10: error: incompatible types when assigning to type ‘double’ from type ‘void *’
detruire.c:11: error: incompatible types when assigning to type ‘char[15]’ from type ‘void *’
detruire.c:12: error: incompatible types when assigning to type ‘double’ from type ‘void *’
detruire.c:14: warning: ‘return’ with a value, in function returning void
voici mon main
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
#include <stdio.h>
#include "element.h"
#include <stdlib.h>
main()
{
Element *element ;
int j;
int x;
printf("Introduire le nombre d'element :");
scanf("%d", &x);
element = construire(x);
ecrire(element,x);
printf("\nElement a detruire :");
scanf("%d", &j);
element = detruire(element,j);
ecrire(element,j);
return(0) ;
}
#include "element.h"
#include <stdio.h>
#include <stdlib.h>
Element *construire(int x)
{
Element *elt ;
printf("coucou\n");
elt =(Element *) malloc( x * sizeof(Element));
int i = 0;
printf("entrer les informations sur les planetes:\n");
for(i; i < x;i++){
if (elt) {
printf("diametre :");
scanf("%lf", &(elt[i].diametre)) ;
printf("nom :");
scanf("%s", elt[i].nom) ;
printf("Distance:");
scanf("%lf", &(elt[i].distance)) ;
}
}
return(elt) ;
} |
et voici la definition de ma structure .
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
struct planete {
double diametre ;
char nom[15] ;
double distance ;
} ;
typedef struct planete Element ;
Element *construire(int x);
void ecrire(Element element[], int x);
Element *detruire(Element element[],int x); |
voici le code pour detruire une structure dans un tableau de structure .
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #include "element.h"
#include <stdio.h>
#include <stdlib.h>
Element *detruire(Element element[],int x)
{
printf("au revoir\n");
element[x].diametre = NULL;
element[x].nom = NULL;
element[x].distance = NULL;
return(element) ;
} |
ps : je debute en c
merci de m'aider